MySQL 中 PHP stripos() 等效函式是什麼?


MySQL 中的 stripos() 等效函式是 INSTR(),它返回一個字串在另一個字串中第一次出現的位置。語法如下 −

select instr(yourColumnName,yourWord) As anyAliasName from yourTableName;

讓我們首先建立一個表格 −

mysql> create table DemoTable
   -> (
   -> Title text
   -> );
Query OK, 0 rows affected (1.22 sec)

使用插入命令在表中插入一些記錄 −

mysql> insert into DemoTable values('MySQL is my favourite subject');
Query OK, 1 row affected (0.13 sec)

mysql> insert into DemoTable values('MongoDB is not my favourite subject');
Query OK, 1 row affected (0.20 sec)

使用 select 語句從表中顯示所有記錄 −

mysql> select *from DemoTable;

輸出

+-------------------------------------+
| Title                               |
+-------------------------------------+
| MySQL is my favourite subject       |
| MongoDB is not my favourite subject |
+-------------------------------------+
2 rows in set (0.00 sec)

以下是對返回字串第一次出現的位置的 MySQL stripos() 等效函式的查詢 −

mysql> select instr(Title,'favourite') As Position from DemoTable;

輸出

+----------+
| Position |
+----------+
| 13       |
| 19       |
+----------+
2 rows in set (0.00 sec)

更新於: 2019-07-30

106 次瀏覽

開啟您的 職業

透過完成本課程獲得認證

開始
廣告
© . All rights reserved.