mysql 強大的trim() 函數_Mysql

來源:互聯網
上載者:User
mysql中的去除左空格函數:
LTRIM(str)
Returns the string str with leading space characters removed.

以下是程式碼片段:

複製代碼 代碼如下:

mysql> SELECT LTRIM(' barbar');
-> 'barbar'


This function is multi-byte safe.

mysql中的去除右空格函數:
RTRIM(str)
Returns the string str with trailing space characters removed.

以下是程式碼片段:

複製代碼 代碼如下:

mysql> SELECT RTRIM('barbar ');
-> 'barbar'


This function is multi-byte safe.

trim函數可以過濾指定的字串:
完整格式:TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM] str)
簡化格式:TRIM([remstr FROM] str)

Returns the string str with all remstr prefixes or suffixes removed. If none of the specifiers BOTH, LEADING, or TRAILING is given, BOTH is assumed. remstr is optional and, if not specified, spaces are removed.

以下是程式碼片段:

複製代碼 代碼如下:

mysql> SELECT TRIM(' bar '); //預設刪除前後空格
-> 'bar'
mysql> SELECT TRIM(LEADING ',' FROM ',,barxxx'); //刪除指定首字元 如',‘
-> 'barxxx'
mysql> SELECT TRIM(BOTH ',' FROM ',,bar,,,'); //刪除指定首尾字元
-> 'bar'
mysql> SELECT TRIM(TRAILING ',' FROM 'barxxyz,,');
-> 'barxxyz'


複製代碼 代碼如下:

mysql> UPDATE table SET `field`=TRIM(TRAILING ',' FROM `FIELD`) WHERE WHERE `FIELD` LIKE '%,';


This function is multi-byte safe.

替換資料庫中欄位的最後一個分頁符

複製代碼 代碼如下:

UPDATE [!db.pre!]ecms_news_data_1 SET `newstext`=TRIM(TRAILING '[!--empirenews.page--]' FROM `newstext`) WHERE id=585;
SELECT TRIM(TRAILING '[!--empirenews.page--]' FROM `newstext`) AS newstex FROM [!db.pre!]ecms_news_data_1 WHERE id=585;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.