Versions available for this page: CUBRID 8.2.1 | CUBRID 8.3.0 | CUBRID 8.3.1 | CUBRID 8.4.0 | CUBRID 8.4.1 | CUBRID 8.4.3 | CUBRID 9.0.0 |
The SUBSTR function extracts a character string with the length of substring_length from a position, position, within character string, string, and then returns it.
Note In the earlier versions of CUBRID, the starting position and string length are calculated in byte unit, not in character unit. Therefore, in a multi-byte character set, you must specify the parameter in consideration of the number of bytes representing a single character.
SUBSTR( string, position [, substring_length])
string:
• character string
• bit string
• NULL
position:
• integer
• NULL
substring_length:
• integer
--character set is UTF-8 for Korean characters
--it returns empty string when substring_length is 0
SELECT SUBSTR('12345abcdeabcde',6, 0);
substr('12345abcdeabcde', 6, 0)
======================
''
--it returns 4-length substrings counting from the position
SELECT SUBSTR('12345abcdeabcde', 6, 4), SUBSTR('12345abcdeabcde', -6, 4);
substr('12345abcdeabcde', 6, 4) substr('12345abcdeabcde', -6, 4)
============================================
'abcd' 'eabc'
--it returns substrings counting from the position to the end
SELECT SUBSTR('12345abcdeabcde', 6), SUBSTR('12345abcdeabcde', -6);
substr('12345abcdeabcde', 6) substr('12345abcdeabcde', -6)
============================================
'abcdeabcde' 'eabcde'
-- it returns 4-length substrings counting from 11th position
SELECT SUBSTR ('12345가나다라마가나다라마', 11 , 4);
substr('12345가나다라마가나다라마', 11 , 4)
======================
'가나다라'