我想更改job_title
中的所有單詞。使用MySQL UPDATE多次更新同一行中的同一列
在job_title
我下面的例子是:
在86619
行art department work experience/greenswoman
。
下面是代碼:
Set autocommit = 1;
UPDATE tvt_job_title SET job_title = REPLACE(LOWER(job_title),'art','Art') WHERE job_title_id = 86619; UPDATE tvt_job_title SET job_title = REPLACE(LOWER(job_title),'work','Work') WHERE job_title_id = 86619; UPDATE tvt_job_title SET job_title = REPLACE(LOWER(job_title),'department','Department') WHERE job_title_id = 86619; UPDATE tvt_job_title SET job_title = REPLACE(LOWER(job_title),'experience','Experience') WHERE job_title_id = 86619; UPDATE tvt_job_title SET job_title = REPLACE(LOWER(job_title),'greenswoman','Greenswoman') WHERE job_title_id = 86619;
select job_title from tvt_job_title where job_title_id = 86619;
結果:
art department work experience/Greenswoman
只有Greenswoman得到糾正!爲什麼不是所有的單詞都得到糾正?
輸出:
UPDATE tvt_job_title SET job_title = REPLACE(LOWER(job_title),'art','Art') WHERE job_title_id = 86619 1 row(s) affected Rows matched: 1 Changed: 1 Warnings: 0
UPDATE tvt_job_title SET job_title = REPLACE(LOWER(job_title),'work','Work') WHERE job_title_id = 86619 1 row(s) affected Rows matched: 1 Changed: 1 Warnings: 0
UPDATE tvt_job_title SET job_title = REPLACE(LOWER(job_title),'department','Department') WHERE job_title_id = 86619 1 row(s) affected Rows matched: 1 Changed: 1 Warnings: 0
UPDATE tvt_job_title SET job_title = REPLACE(LOWER(job_title),'experience','Experience'), abbreviation = REPLACE(LOWER(abbreviation),'experience','Experience') WHERE job_title_id = 86619 1 row(s) affected Rows matched: 1 Changed: 1 Warnings: 0
UPDATE tvt_job_title SET job_title = REPLACE(LOWER(job_title),'greenswoman','Greenswoman'), abbreviation = REPLACE(LOWER(abbreviation),'greenswoman','Greenswoman') WHERE job_title_id = 86619 1 row(s) affected Rows matched: 1 Changed: 1 Warnings: 0
select job_title from tvt_job_title where job_title_id = 86619 1 row(s) returned
它看起來像你特別過濾所有'job_title_id = 86619'。那會是「Greenswoman」的'job_title_id'嗎? – theGleep
是的。我想更改行86619的job_title列中的所有單詞。LOWER()是此處出現問題的原因。我試圖做一個不區分大小寫的REPLACE,這樣greensWoman會變成Greenswoman。我想要的結果是'藝術部門工作經驗/綠女' –
啊......這是有道理的。您在單個字段中更新多個值,而不是多個字段。 – theGleep