メインコンテンツまでスキップ
バージョン: V1.4.0

SUBSTR

宣言​

SUBSTR(str, pos)
SUBSTR(str, pos, len)
SUBSTR(str FROM pos)
SUBSTR(str FROM pos FOR len)

説明​

str のサブ文字列を返します。開始位置は pos、長さは len です。パラメータに NULL が含まれる場合、NULL を返します。

  • len を指定しない場合、返されるサブ文字列は pos から str の終端までの範囲となります。

  • pos の値が負数の場合、str の末尾から頭方向に逆順にして開始位置を決定します。

  • len が0以下、または pos が指定する開始位置が無効な場合、空文字列を返します。

例​

SELECT
SUBSTR('abcdefg', 3),
SUBSTR('abcdefg', 3, 2),
SUBSTR('abcdefg', -3),
SUBSTR('abcdefg', 3, -2),
SUBSTR('abcdefg' from -4 for 2)
\G
*************************** 1. row ***************************
SUBSTR('abcdefg', 3): cdefg
SUBSTR('abcdefg', 3, 2): cd
SUBSTR('abcdefg', -3): efg
SUBSTR('abcdefg', 3, -2):
SUBSTR('abcdefg' from -4 for 2): de
1 row in set (0.001 sec)