Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> MySQL

ค่า false ใน MySQL ตรงกับสตริงได้อย่างไร?

ใน MySQL FALSE = 0 เมื่อบวกสตริงด้วย 0 จะแปลงเป็นตัวเลข (取得ตัวเลขนำหน้า)

สร้างตารางและเพิ่มข้อมูลสตริงผสมตัวเลข

mysql> create table DemoTable804 ( Id varchar(100) ); 
Query OK, 0 rows affected (0.66 sec)

mysql> insert into DemoTable804 values('101John'); Query OK, 1 row affected (0.20 sec)
mysql> insert into DemoTable804 values('Carol1002'); Query OK, 1 row affected (0.22 sec)
mysql> insert into DemoTable804 values('1000'); Query OK, 1 row affected (0.15 sec)
mysql> insert into DemoTable804 values('1010Bob'); Query OK, 1 row affected (0.10 sec)

คิวรี 0 + Id (เทียบเท่า FALSE + Id)

mysql> select 0+Id from DemoTable804;
+------+
| 0+Id |
+------+
| 101  |
| 0    |
| 1000 |
| 1010 |
+------+
4 rows in set, 2 warnings (0.00 sec)

คำอธิบาย: '101John' → 101, 'Carol1002' → 0 (ขึ้นต้นตัวอักษร), '1000' → 1000, '1010Bob' → 1010