oracle 如何截取一个字符串直到后面全是0为止
例如id101332000000005130201100000035900000000000截取之后想要的结果为10133251302011359...
例如 id
10133200000000
51302011000000
35900000000000
截取之后想要的结果为
101332
51302011
359 展开
10133200000000
51302011000000
35900000000000
截取之后想要的结果为
101332
51302011
359 展开
展开全部
存储过程做吧。
录入数据
create table test
(id varchar2(100));
insert into test values ('10133200000000');
insert into test values ('51302011000000');
insert into test values ('35900000000000');
commit;
执行代码:
declare
v_str varchar2(100);
v_str1 varchar2(100);
v_id_reverse varchar2(100);
v_s int;
cursor c_str is
select id from test;
begin
open c_str;
loop
fetch c_str
into v_str;
exit when c_str%notfound;
select reverse(v_str) into v_id_reverse from dual;
v_s := 1;
loop
select substr(v_id_reverse, v_s, 1) into v_str from dual;
if v_str = 0 then
v_s := v_s + 1;
else
select reverse(substr(v_id_reverse,
v_s,
length(v_id_reverse) - v_s + 1))
into v_str1
from dual;
exit;
end if;
end loop;
dbms_output.put_line(v_str1);
end loop;
close c_str;
end;
执行结果:
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询