0
如何以保持原始值的方式更新SQL中的字段並僅爲其添加前綴或後綴?通過在SQL中擴展原始值來更新字段
update mytable set myfield = 'ABC'+myfield where id = 123
不起作用。
任何想法?
如何以保持原始值的方式更新SQL中的字段並僅爲其添加前綴或後綴?通過在SQL中擴展原始值來更新字段
update mytable set myfield = 'ABC'+myfield where id = 123
不起作用。
任何想法?
你有正確的想法。只需使用MySQL的語法:
update mytable
set myfield = concat('ABC', myfield)
where id = 123 ;
注意:如果myfield
可能是NULL
,那麼你可能會想:
update mytable
set myfield = concat('ABC', coalesce(myfield, ''))
where id = 123 ;
試試這個,使用concat
功能:
update mytable set myfield = concat('ABC',myfield) where id = 123