Disadvantages of quoting integers in a Mysql query?

后端 未结 4 1268
天涯浪人
天涯浪人 2020-12-06 18:56

I am curious about the disadvantage of quoting integers in MYSQL queries

For example

SELECT col1,col2,col3 FROM table WHERE col1=\'3\';
4条回答
  •  时光说笑
    2020-12-06 19:50

    Strings also have a different sort order from numbers.

    Compare:

    SELECT 312 < 41
    

    (yields 0, because 312 numerically comes after 41)

    to:

    SELECT '312' < '41'
    

    (yields 1, because '312' lexicographically comes before '41')

    Depending on the way your query is built using quotes might give wrong results or none at all.

    Numbers should be used as such, so never use quotes unless you have a special reason to do so.

提交回复
热议问题