MySQL 中 WHERE 子句中的自动字符串转整型用于获取特定的 id
如果字符串以整数开头,那么它将字符串转换为整数,否则不会。我们首先创建一个 -
mysql> create table DemoTable1390 -> ( -> StudentId varchar(20) -> ); Query OK, 0 rows affected (0.93 sec)
使用 insert 在表中插入一些记录 -
mysql> insert into DemoTable1390 values('563_John');
Query OK, 1 row affected (0.10 sec)
mysql> insert into DemoTable1390 values('1001_Carol_Taylor');
Query OK, 1 row affected (0.08 sec)
mysql> insert into DemoTable1390 values('David_Miller_789');
Query OK, 1 row affected (0.07 sec)
mysql> insert into DemoTable1390 values('456_AdamSmith');
Query OK, 1 row affected (0.11 sec)使用 select 显示表中的所有记录 -
mysql> select * from DemoTable1390;
这将产生以下输出 -
+-------------------+ | StudentId | +-------------------+ | 563_John | | 1001_Carol_Taylor | | David_Miller_789 | | 456_AdamSmith | +-------------------+ 4 rows in set (0.00 sec)
以下是 where 子句中自动字符串转整型的查询,用于获取特定的 -
mysql> select * from DemoTable1390 where StudentId=456;
这将产生以下输出 -
+---------------+ | StudentId | +---------------+ | 456_AdamSmith | +---------------+ 1 row in set, 4 warnings (0.02 sec)
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP