Oracle substr函数用法
取得字符串中指定起始位置和长度的字符串 substr( string, start_position, [ length ] );
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 < 0
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 substr函数的使用方法,包括其参数解释、不同参数值下的操作示例,以及如何在SQL查询中有效应用。通过具体实例,帮助读者理解如何精确地截取字符串,满足数据库操作中的特定需求。
13万+

被折叠的 条评论
为什么被折叠?



