SUB_REPLACE
説明
sub_replace関数は、文字列内の部分文字列を置換するために使用されます。置換される部分文字列と、それを置き換える対象の文字列を指定できます。この関数は、str内のstartから始まり長さlenの部分文字列をnew_strで置換した新しい文字列を返します。startまたはlenが負の整数の場合、NULLを返します。lenのデフォルト値はnew_strの長さです。
構文
sub_replace(<str>, <new_str>, [ ,<start> [ , <len> ] ])
パラメータ
| Parameter | デスクリプション |
|---|---|
<str> | 置換が行われる対象の文字列 |
<new_str> | 指定された部分文字列を置き換える文字列 |
<start> | startは置換操作が開始される位置で、文字列内のどの位置から置換を開始するかを示す |
<len> | lenは置換される部分文字列の長さを指定するオプションパラメータ |
Return Value
置換後の文字列を返します。
Examples
select sub_replace("this is origin str","NEW-STR",1);
+-------------------------------------------------+
| sub_replace('this is origin str', 'NEW-STR', 1) |
+-------------------------------------------------+
| tNEW-STRorigin str |
+-------------------------------------------------+
select sub_replace("doris","***",1,2);
+-----------------------------------+
| sub_replace('doris', '***', 1, 2) |
+-----------------------------------+
| d***is |
+-----------------------------------+