加入收藏 | 设为首页 | 会员中心 | 我要投稿 衡阳站长网 (https://www.0734zz.cn/)- 数据集成、设备管理、备份、数据加密、智能搜索!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

MySQL 寻常str函数

发布时间:2022-07-08 20:30:09 所属栏目:MySql教程 来源:互联网
导读:MySQL常见的字符串函数 整理自官档。 1.1 SUBSTR or SUBSTRING SUBSTR(str,pos), SUBSTR(str FROM pos),SUBSTR(str,pos,len), SUBSTR(str FROM pos FOR len) SUBSTR() is a synonym for SUBSTRING(). SUBSTRING(str FROM pos FOR len) The forms without a l
  MySQL常见的字符串函数
 
  整理自官档。
 
  1.1     SUBSTR or SUBSTRING
  SUBSTR(str,pos), SUBSTR(str FROM pos),SUBSTR(str,pos,len), SUBSTR(str FROM
 
  pos FOR len)
 
  SUBSTR() is a synonym for SUBSTRING().
 
  SUBSTRING(str FROM pos FOR len)
 
  The forms without a len argument return asubstring from string str starting at position pos.
 
  The forms with a len argument return asubstring len characters long from string str, starting at
 
  position pos. The forms that use FROM arestandard SQL syntax. It is also possible to use a negative
 
  value for pos. In this case, the beginningof the substring is pos characters from the end of the
 
  string, rather than the beginning. Anegative value may be used for pos in any of the forms of this
 
  function.
 
  For all forms of SUBSTRING(), the positionof the first character in the string from which the
 
  substring is to be extracted is reckoned as1.
 
  mysql> SELECTSUBSTRING('Quadratically',5);
 
  -> 'ratically'
 
  mysql> SELECT SUBSTRING('foobarbar' FROM4);
 
  -> 'barbar'
 
  mysql> SELECTSUBSTRING('Quadratically',5,6);
 
  -> 'ratica'
 
  mysql> SELECT SUBSTRING('Sakila', -3);
 
  -> 'ila'
 
  mysql> SELECT SUBSTRING('Sakila', -5,3);
 
  -> 'aki'
 
  mysql> SELECT SUBSTRING('Sakila' FROM -4FOR 2);
 
  -> 'ki'
 
  This function is multibyte safe.
 
  If len is less than 1,the result is the empty string.
 
  1.2    LENGTH
  LENGTH(str) 返回字节数
 
  Returns the length of the string str,measured in bytes. A multibyte character counts as multiple
 
  bytes. This means that for a stringcontaining five 2-byte characters, LENGTH() returns 10, whereas
 
  CHAR_LENGTH() returns 5.
 
  mysql> SELECT LENGTH('text');

(编辑:衡阳站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读