Home > database >  The mysql database where '1-1 in (1) why is true
The mysql database where '1-1 in (1) why is true

Time:10-15

'where's 1-1 in (1) | true
'where's 1-1 in (' 1') | false
Where '2-1 in (1) | false

CodePudding user response:

Select '1 1=1 the result is true, because the database varchar transformed into int, transformed into 1-1 1

CodePudding user response:

The following content, if you can understand, you have the answer,
1, IN the content of the back, if it is digital, so will the IN front of the character content (quoted), converted to digital,
2, in character converted to digital, from the left, one by one, transformation, meet the number, just returned directly,
If 'ab', a length is a number greater than or equal to 1, b is a non-numeric characters, then 'ab' convert digital results, is a,
Can try the following
SELECT the CAST (' 5-5 'AS SIGNED),' 5-1 + 0

Summary, MYSQL, even if a character is digital, also want to quotes,
Avoid the following problem
SELECT the FROM 0 DUAL WHERE '1 a=1

CodePudding user response:

CodePudding user response:

refer to the second floor AHUA1001 response:
the following content, if you can understand, you have the answer,
1, IN the content of the back, if it is digital, so will the IN front of the character content (quoted), converted to digital,
2, in character converted to digital, from the left, one by one, transformation, meet the number, just returned directly,
If 'ab', a length is a number greater than or equal to 1, b is a non-numeric characters, then 'ab' convert digital results, is a,
Can try the following
SELECT the CAST (' 5-5 'AS SIGNED),' 5-1 + 0

Summary, MYSQL, even if a character is digital, also want to quotes,
Avoid the following problem
SELECT the FROM 0 DUAL WHERE '1 a=1

Regardless of is the same before and after the results, to a reasonable explanation is before the string is converted to a strongly typed, transformation rules are from first to last in front of the Numbers in a row, feeling should be no problem, the type int to char

CodePudding user response:

Mysql> Select '1 1';
+ +
-- -- -- -- --| | 1-1
+ +
-- -- -- -- --| | 1-1
+ +
-- -- -- -- --1 row in the set (0.00 SEC)

Mysql> Select '1-1-1;
+ + -- -- -- -- -- -- -- -- --
| | '1-1-1
+ + -- -- -- -- -- -- -- -- --
| | 0
+ + -- -- -- -- -- -- -- -- --
1 row in the set, 1 warning (0.00 SEC)

Mysql> Select '5-1-1;
+ + -- -- -- -- -- -- -- -- --
| | '5-1-1
+ + -- -- -- -- -- -- -- -- --
4 | |
+ + -- -- -- -- -- -- -- -- --
1 row in the set, 1 warning (0.00 SEC)

Mysql> Select '1-5' - 1;
+ + -- -- -- -- -- -- -- -- --
| | '1-5-1
+ + -- -- -- -- -- -- -- -- --
| | 0
+ + -- -- -- -- -- -- -- -- --
1 row in the set, 1 warning (0.00 SEC)

To sum up:
1. If a separate output is said is a string
2. If the arithmetic operations are directly manipulate
3. If a special symbol operation directly from left
  • Related