SELECT substr('helloword',
-1,
5) from
dual
从右边开始截取5位。
Oracle
截取字符串
1.
SUBSTR:取子字符串,从“起始位置”开始,取“多少"个,当起始位置为负数的时候,从右边开始查找。
SUBSTR(源字符串,起始位置,要取多少位)
例:Select
SUBSTR('ORC+001',1,3)
From
dual;
返回的是“ORC”
Select
SUBSTR('ORC+001',-5,3)
From
dual;
返回的是“ORC”
2.
INSTR:默认查找顺序为从左到右。当起始位置为负数的时候,从右边开始查找。INSTR(源字符串,
目标字符串,
起始位置,
匹配序号)
例:Select
INSTR('ORC+001','+',1,1)
From
dual
;
返回的是"4",如果该字符串没有匹配字符返回的是“0”。
--创建一张临时表,用来存在
1,23,456,7890这个字符串
create
table
test_20110420(strint_test
varchar2(50));
--把1,23,456,7890
这个字符串写入到临时表
insert
into
test_20110420
values('1,23,456,7890');
--一个sql语句查询出来
select
substr(a.strint_test,1,instr(a.strint_test,',')-1)
from
test_20110420
a
union
all
select
substr(a.strint_test,instr(a.strint_test,',',1,1)+1,instr(a.strint_test,',',1,2)-1-instr(a.strint_test,',',1,1))
from
test_20110420
a
union
all
select
substr(a.strint_test,instr(a.strint_test,',',1,2)+1,instr(a.strint_test,',',1,3)-1-instr(a.strint_test,',',1,2))
from
test_20110420
a
union
all
select
substr(a.strint_test,instr(a.strint_test,',',1,3)+1)
from
test_20110420
a
;