mysql忽略中英文括号_MySQL查询删除方括号之间的文本?
讓我們首先創建一個表-create?table?DemoTable
->?(
->?Name?text
->?);
使用插入命令在表中插入一些記錄-insert?into?DemoTable?values('John?[John]?Smith');
insert?into?DemoTable?values('[Carol]?Carol?Taylor');
insert?into?DemoTable?values('David?[Miller]?Miller');
使用select語句顯示表中的所有記錄-select?*from?DemoTable;+-----------------------+
|?Name??????????????????|
+-----------------------+
|?John?[John]?Smith?????|
|?[Carol]?Carol?Taylor??|
|?David?[Miller]?Miller?|
+-----------------------+
3?rows?in?set?(0.00?sec)
以下是刪除方括號之間的文本的查詢-select?replace(Name,substring(Name,locate('[',?Name),?LENGTH(Name)
->?-?locate(']',?reverse(Name))?-?locate('[',?Name)?+?2),?'')?as?Name
->?from?DemoTable;
這將產生以下輸出-+---------------+
|?Name??????????|
+---------------+
|?John?Smith????|
|?Carol?Taylor??|
|?David?Miller??|
+---------------+
3?rows?in?set?(0.03?sec)
總結
以上是生活随笔為你收集整理的mysql忽略中英文括号_MySQL查询删除方括号之间的文本?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux中atoi函数的实现 值得借鉴
- 下一篇: sqlplus命令连接oracle数据库