varchar字符串分割

刚写的,备份下

 

declare
     str varchar2(100) := 'ids=121|age=1356|password=gaowei';
     temp varchar2(200) := '';
     s_current varchar2(200) := '';    -- 当前遍历的字符串
     start_index int:=1;               -- 开始索引
     end_index int := 0;               -- 截取多少个字符串
begin
     -- 分隔str
     for i in 1..length(str) loop
         end_index := end_index + 1;   -- 循环一次就加一次,比如第一次循环那么就截取1个字符串
         s_current :=  substr(str,i,1);  -- 拿到当前字符串 'i'
         if (s_current = '|') or i = length(str) then
            --dbms_output.put_line(start_index || '==' || end_index);
            temp := substr(str,start_index,end_index);
            start_index := i+1;
            end_index := 0;            
            if i <> length(str) then
                dbms_output.put_line(substr(temp,1,length(temp)-1)); 
--                dbms_output.put_line(temp);                  
            else
                dbms_output.put_line(temp);
            end if;          
         end if;         
     end loop;
end;

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值