Home > Software design >  sql like operator on integer
sql like operator on integer

Time:11-12

I google search 'sql like operator on integer', all tell me to use

   where cast ( int_field as text ) like '0.%'

Warning: reality is opposite position!!!

why I can use 'like' operator on integer, decimal, directly, without cast?

here is my mysql example:

enter image description here

another example:

enter image description here

integer type

enter image description here

CodePudding user response:

This is handled by an implicit type conversion in MySQL.

When you use a numeric type in a string context, i.e. comparing it to a string, then the numeric is implicitly converted to a string, then the comparison is evaluated. You don't need to use CAST() first.

This is documented for MySQL here: enter image description here

first paragraph again... "If any one of the arguments isn't of character string data type, the SQL Server Database Engine converts it to character string data type, if it's possible

enter image description here

enter image description here

  • Related