Create or replace type mytable as table of varchar2 (100)
Create or replace function split (SRC varchar2, delimiter varchar2)
Return mytable is
Psrc varchar2 (500 );
A mytable: = mytable ();
I number: = 1 ;--
J number: = 1;
Begin
Psrc: = rtrim (ltrim (SRC, delimiter), delimiter );
Loop
I: = instr (psrc, delimiter, J );
-- Dbms_output.put_line (I );
If I> 0 then
A. Extend;
A (A. Count): = trim (substr (psrc, J, I-j ));
J: = I + 1;
-- Dbms_output.put_line (a (A. Count-1 ));
End if;
Exit when I = 0;
End loop;
If j <length (psrc) then
A. Extend;
A (A. Count): = trim (substr (psrc, J, length (psrc) + 1-j ));
End if;
Return;
End;
Create or replace function split (SRC varchar2, delimiter varchar2) return mytable is
Psrc varchar2 (500); A mytable: = mytable (); I number: = 1 ;--
J number: = 1;
Begin
Psrc: = rtrim (ltrim (SRC, delimiter), delimiter); loop I: = instr (psrc, delimiter, J );
-- Dbms_output.put_line (I );
If I> 0 then A. Extend; A (A. Count): = trim (substr (psrc, J, I-j); j: = I + 1;
-- Dbms_output.put_line (a (A. Count-1 ));
End if; exit when I = 0;
End loop; If j <length (psrc) Then. extend; A (. count): = trim (substr (psrc, J, length (psrc) + 1-j ));
End if; return;
End;
/
An array is used as a query condition for select in.
Select * from student where ID in (select * from table (cast (split ('201312', ',')
Mytable); select * from student where ID in (select * from table (cast (split ('20170101', ',')
Mytable )));
select * from student where ID in (select ID from student where id = '001' Union select * from table (cast (split ('123 ',',') as
mytable)