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
500 views
in Technique[技术] by (71.8m points)

mysql update and更新有问题,为什么mysql不报语法错误

update a set name = '123' and age = 20

mysql的这个更新语句有问题,没什么疑问,我的疑问是为什么mysql不报语法错误?


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

1 Answer

0 votes
by (71.8m points)

因为语法没问题,MySQL 会按照运算符优先级来解析这条语句,实际是:

UPDATE `a` SET `name` = ('123' AND `age` = 20);

赋值语句结果为 true,一个非空的字符串转为 Boolean 也为 true,两个 true逻辑和运算,结果还是 true

所以你这条语句实际上等效于:

UPDATE `a` SET `name` = true;

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

...