首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

varchar字符串瓜分

2012-07-20 
varchar字符串分割刚写的,备份下?declare???? str varchar2(100) : ids121|age1356|passwordgaowei

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;

?

?

热点排行