Oracle substr函数用法取得字符串中指定起始位置和长度的字符串 substr( string, start_position, [ length ] );substr(字符串,
Oracle substr函数用法
取得字符串中指定起始位置和长度的字符串 substr( string, start_position,
substr(字符串,截取开始位置,截取长度) //返回截取的字;
start_position为正时,从左往右获取字符串;
start_position为负时,从右往左获取字符串;
start_position为0时,从字符串开始位置获取字符串;
Examples:
1、start_position = 0
SELECT SUBSTR('hello',0,3) FROM dual; --hel
SELECT SUBSTR('hello',0,6) FROM dual; --hello
SELECT SUBSTR('hello',0,0) FROM dual; --null
SELECT SUBSTR('hello',0) FROM dual; --hello
2、start_position > 0
SELECT SUBSTR('hello',1,0) FROM dual; --null
SELECT SUBSTR('hello',1,2) FROM dual; --he
SELECT SUBSTR('hello',1,6) FROM dual; --hello
SELECT SUBSTR('hello',1) FROM dual; --hello
3、start_position
SELECT SUBSTR('hello',-3) FROM dual; --'llo'
SELECT SUBSTR('hello',-1) FROM dual; --'o'
SELECT SUBSTR('hello',-3,2) FROM dual; --'ll'
SELECT SUBSTR('hello',-7) FROM dual; --null
相关阅读:
Oracle函数之Replace()
Oracle函数大全
Oracle函数之case和decode的用法区别及性能比较
Oracle函数和存储过程简单实例
Oracle函数 通过秒数或分钟数获取时间段
,