您好,欢迎来到意榕旅游网。
搜索
您的当前位置:首页类似于split的作用将字符串,分隔开成字符数组

类似于split的作用将字符串,分隔开成字符数组

来源:意榕旅游网

也是从一个开源的软件中看到的 就冒昧的拿了出来 PL/SQL split procedure comma_to_arr(list in varchar2, arr out col_head_arr, lenarr out integer) is type col_head_arr is table of varchar2(50) index by binary_integer; l_arr col_head_arr;--字符数

也是从一个开源的软件中看到的 就冒昧的拿了出来

PL/SQL split $velocityCount-->
 procedure comma_to_arr(list in varchar2,
 arr out col_head_arr,
 lenarr out integer) is
 type col_head_arr is table of varchar2(50) index by binary_integer;
 l_arr col_head_arr;--字符数组
 i integer;--
 str_start integer;
 arr_counter integer;
 begin
 -- first check if it is null
 --如果为空 就直接返回空的数组 ,标记长度为0
 if length(list) = 0 then
 arr := l_arr;
 lenarr := 0;
 return;
 end if;
 
 i := 1;
 str_start := 1;
 arr_counter := 0;
 --循环条件 字符扫描位置小于字符长度+1
 while i <= length(list) + 1 loop
 --如果字符长度大于 字符长度 或者是 字符串的第i位是i
 if i > length(list) or substr(list, i, 1) = ',' then
 --要数组长度递增
 arr_counter := arr_counter + 1;
 --将 浮标位置开始 以及到 ,之间的 字符保存
 l_arr(arr_counter) := substr(list, str_start, i - str_start);
 --将浮标 设定为,后的下一个字符 
 str_start := i + 1;
 end if;
 --移动 字符扫描位置
 i := i + 1;
 end loop;
 arr := l_arr;
 lenarr := arr_counter;
 end;

Copyright © 2019- yrrf.cn 版权所有

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务