--Return integer as result
create type myScalarType as object
( dp int)
/
create type myTableType as table of myScalarType
/
create or replace function parse( p_dp in varchar2 )
return myTAbleType
PIPELINED
as
l_dp long := p_dp || ',';
n number;
l_rec myScalarType := myScalarType(null);
begin
loop
n := instr( l_dp, ',' );
if ( nvl(n,0) > 0 )
then
l_rec.dp := substr( l_dp, 1, n-1 );
l_dp := substr( l_dp, n+1 );
else
l_rec.dp := null;
end if;
exit when l_rec.dp is null ;
pipe row( l_rec );
end loop;
return;
end;
/
Test
SQL> select * from TABLE( parse('1,1,1,1,2,2,3,3,3,1,1,4,4'))
---- Return Varchar2 values as result
CREATE TYPE MYSCALARTYPE_V AS OBJECT
( DP VARCHAR2(200))
/
CREATE OR REPLACE TYPE MYTABLETYPE_V AS TABLE OF MYSCALARTYPE_V
/
create function Get_var_to_var( p_dp in long )
return myTableType_v
PIPELINED
as
l_dp long := p_dp || ',';
n number;
l_rec MYSCALARTYPE_V := MYSCALARTYPE_V(null);
begin
loop
n := instr( l_dp, ',' );
if ( nvl(n,0) > 0 )
then
l_rec.dp := substr( l_dp, 1, n-1 );
l_dp := substr( l_dp, n+1 );
else
l_rec.dp := null;
end if;
exit when l_rec.dp is null ;
---dbms_output.put_line(l_rec.dp);
pipe row( l_rec );
end loop;
return;
end;
TestSQL> select * from TABLE(Get_var_to_var('dilip,sagar,dil'));
create type myScalarType as object
( dp int)
/
create type myTableType as table of myScalarType
/
create or replace function parse( p_dp in varchar2 )
return myTAbleType
PIPELINED
as
l_dp long := p_dp || ',';
n number;
l_rec myScalarType := myScalarType(null);
begin
loop
n := instr( l_dp, ',' );
if ( nvl(n,0) > 0 )
then
l_rec.dp := substr( l_dp, 1, n-1 );
l_dp := substr( l_dp, n+1 );
else
l_rec.dp := null;
end if;
exit when l_rec.dp is null ;
pipe row( l_rec );
end loop;
return;
end;
/
Test
SQL> select * from TABLE( parse('1,1,1,1,2,2,3,3,3,1,1,4,4'))
---- Return Varchar2 values as result
CREATE TYPE MYSCALARTYPE_V AS OBJECT
( DP VARCHAR2(200))
/
CREATE OR REPLACE TYPE MYTABLETYPE_V AS TABLE OF MYSCALARTYPE_V
/
create function Get_var_to_var( p_dp in long )
return myTableType_v
PIPELINED
as
l_dp long := p_dp || ',';
n number;
l_rec MYSCALARTYPE_V := MYSCALARTYPE_V(null);
begin
loop
n := instr( l_dp, ',' );
if ( nvl(n,0) > 0 )
then
l_rec.dp := substr( l_dp, 1, n-1 );
l_dp := substr( l_dp, n+1 );
else
l_rec.dp := null;
end if;
exit when l_rec.dp is null ;
---dbms_output.put_line(l_rec.dp);
pipe row( l_rec );
end loop;
return;
end;
TestSQL> select * from TABLE(Get_var_to_var('dilip,sagar,dil'));
No comments:
Post a Comment