This function splits the target string with the specified string and returns the result through the table structure. The code is as follows:CREATE OR REPLACETYPE Str_split is TABLE of VARCHAR2(4000);CREATE OR REPLACE FUNCTIONSplitstr (p_stringinch VARCHAR2, P_delimiterinch VARCHAR2) RETURNstr_split pipelined asV_length Number:=LENGTH (p_string); V_start Number:= 1; V_index Number;BEGIN while(V_start<=v_length) LOOP V_index:=INSTR (p_string, P_delimiter, V_start); IFV_index= 0 Then PIPEROW (SUBSTR (p_string, V_start)); V_start:=V_length+ 1; ELSE PIPEROW (SUBSTR (p_string, V_start, V_index-V_start)); V_start:=V_index+ 1; END IF; ENDLOOP; RETURN;ENDSplitstr; Once created, let's test it, for example, execute the following sql:Select * from Table(Splitstr ('hello,cnblogs!',',') , whose output is a two-row table, such as: the-9-9-11.38. theto display rows to columns:SelectA.column_value V1,b.column_value v2 from (Select * from(SelectRowNum rn,t.* from Table(Splitstr ('hello,cnblogs!',',')) (t)) A, (Select * from(SelectRowNum rn,t.* from Table(Splitstr ('hello,cnblogs!',',')) ( t)) bwhereA.rn=1 andB.rn=2 the-9-9-11.44. -
Oracle Split String function