Should I quote numbers in SQL?

后端 未结 7 1529
逝去的感伤
逝去的感伤 2020-12-06 16:21

I remember reading about quoting stuff when doing a SQL query and that when you quote something, it becomes a string. I also read that numbers should not be quoted. Now, I c

7条回答
  •  無奈伤痛
    2020-12-06 16:50

    You should not quote numbers if you want to treat them as numbers.

    You're correct by remembering that it makes it a string.

    SELECT 10 AS x
    

    is perfectly legal and will return (in most database engines) a column of datatype int (or a variation thereof.)

    If you do this:

    SELECT '10' AS x
    

    instead you'll get a textual data type. This might too be suitable in some cases, but you need to decide whether you want the result as text or as a number.

提交回复
热议问题