如何使用数字搜索 MySQL varchar 列?
mysqlmysqli database更新于 2025/5/27 14:36:17
使用 MySQL 中的 INSERT() 函数。它具有以下参数 −
| Parameter | Description |
|---|---|
| str | String to be modified |
| position | Position where to insert str2 |
| number | Number of characters to replace |
| str2 | String to insert into str |
首先我们创建一个表 −
mysql> create table DemoTable -> ( -> Code varchar(100) -> ); Query OK, 0 rows affected (0.82 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable values('958575/98') ;
Query OK, 1 row affected (0.16 sec)
mysql> insert into DemoTable values('765432/99');
Query OK, 1 row affected (0.19 sec)
mysql> insert into DemoTable values('983456/91');
Query OK, 1 row affected (0.15 sec)
使用 select 语句显示表中的所有记录 −
mysql> select *from DemoTable;
输出
这将产生以下输出 −
+-----------+ | Code | +-----------+ | 958575/98 | | 765432/99 | | 983456/91 | +-----------+ 3 rows in set (0.00 sec)
这是使用数字在 varchar 列上搜索的查询 −
mysql> select *from DemoTable where Code =INSERT(76543299,7,0,'/');
输出
这将产生以下输出 −
+-----------+ | Code | +-----------+ | 765432/99 | +-----------+ 1 row in set (0.00 sec)
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

