mysql: why comparing a 'string' to 0 gives true?

前端 未结 3 970
灰色年华
灰色年华 2020-12-01 13:09

I was doing some MySQL test queries, and realized that comparing a string column with 0 (as a number) gives TRUE!

select \'string\'         


        
3条回答
  •  不知归路
    2020-12-01 13:25

    "Strings are automatically converted to numbers and numbers to strings as necessary." This means that in order to compare a string to a number, it tries to parse a number from the start of the string. In this case there is no number there, so it converts to 0, and 0 = 0 is true.

提交回复
热议问题