Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
757 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 Answer

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%"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...