如何在MySQL varchar列上使用數字進行搜尋?


使用MySQL中的INSERT()函式。它具有以下引數:

引數描述
str要修改的字串
position插入str2的位置
number要替換的字元數
str2要插入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)

更新於: 2020-06-30

246 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始學習
廣告

© . All rights reserved.