GCT1015
这是Oracle的字符串令牌生成器,它比该页面要简单一些,但不知道它是否这么快:create or replace function splitter_count(str in varchar2, delim in char) return int asval int;begin val := length(replace(str, delim, delim || ' ')); return val - length(str); end;create type token_list is varray(100) of varchar2(200);CREATE or replace function tokenize (str varchar2, delim char) return token_list asret token_list;target int;i int;this_delim int;last_delim int;BEGIN ret := token_list(); i := 1; last_delim := 0; target := splitter_count(str, delim); while i <= target loop ret.extend(); this_delim := instr(str, delim, 1, i); ret(i):= substr(str, last_delim + 1, this_delim - last_delim -1); i := i + 1; last_delim := this_delim; end loop; ret.extend(); ret(i):= substr(str, last_delim + 1); return ret;end;您可以像这样使用它:select tokenize('hi you person', ' ') from dual;VARCHAR(hi,you,person)
梵蒂冈之花
我最后用这个create or replace function split( p_list varchar2) return sys.dbms_debug_vc2coll pipelinedis l_idx pls_integer; l_list varchar2(32767) := p_list; l_value varchar2(32767);begin loop l_idx := instr(l_list,','); if l_idx > 0 then pipe row(substr(l_list,1,l_idx-1)); l_list := substr(l_list,l_idx+length(',')); else pipe row(l_list); exit; end if; end loop; return;end split;declareCURSOR c IS select occurrence_num, graphics from supp where graphics is not null and graphics not like ' %';begin FOR r IN c LOOP insert into image (photo_id,report_id, filename) select image_key_seq.nextval photo_id, r.occurrence_num report_id, t.column_value filename from table(split(cast(r.graphics as varchar2(1000)))) t where t.column_value is not null; END LOOP; end ;