Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
702 views
in Technique[技术] by (71.8m points)

mysql - SQL UPDATE with LIKE

I was trying to update approx 20,000 records in a table by using statements like this one, however, I got the message say 0 row(s) affected so it didn't work.

UPDATE nc_files SET title ="Worklog details" WHERE "log_name" LIKE "%PC01%"

The log_name field has all the file names with mixed file extensions and cases ,e.g.

PC01.TXT | Worklog details

PC02.txt | Project Summary

PC03.DOC| Worklog details

PC04.doc| Project Summary

The reason why I need to use LIKE is that the updated file only have file name without extension, e.g.

PC01 | Worklog details

PC02 | Project Summary

How do I update records by using LIKE?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The log_name is a field name, remove literal quotes from it -

UPDATE nc_files SET title ="Worklog details" WHERE log_name LIKE "%PC01%"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...