Hi Gunjan,
Thanks for replying so promptly. Coming from a SQL Server background, PLSQL is a real challenge. I'm getting the following error when I execute my stored proc.
ORA-06502: PL/SQL: numeric or value error: character to number conversion error
ORA-06512: at "PARSELIST", line 23
Here's the code for parseString :
create or replace function parseList(p in varchar2)
return emplist
is
retval emplist := emplist();
nextPos integer := 0;
lastPos integer := 1;
ind binary_integer := 0;
begin
if p is null then
return null;
end if;
loop
nextPos := instr(p, ',' , lastPos);
exit when nextPos = 0;
ind := ind +1;
retval.extend;
retval(ind) := substr(p, lastPos, nextPos-lastPos);
lastPos := nextPos + 1;
end loop;
ind := ind +1;
retval.extend;
retval(ind) := substr(p, lastPos);
return retval;
end;
/
Here's my SP:
CREATE OR REPLACE
PROCEDURE testProc(p_user_id IN varchar2,
p_recordset OUT Types.cursor_type) AS
BEGIN
OPEN p_recordset FOR
select Trim(f.user_id) as "User ID",
Trim(f.shell_desc) as "Shell Desc",
Trim(f.tran_profile) as "Tran Profile",
Trim(f.field_profile) as "Field Profile",
Trim(f.port_profile) as "Port Profile",
Trim(f.supervisor_shell) as "Supervisor Shell",
Trim(f.lvl) as "lvl"
from fdr_profiles f
where ((p_user_id = '' OR p_user_id IS NULL)
OR lower(rtrim(f.user_id)) in
(select * from table( cast ( parseList('p_user_id')
as empList)))
)
order by f.user_id, f.field_profile;
END testProc;
/
I execute is as follows :
DECLARE
v_cursor Types.cursor_type;
user_id fdr_profiles.user_id%TYPE;
shell_desc fdr_profiles.shell_desc%TYPE;
tran_profile fdr_profiles.tran_profile%TYPE;
fld_profile fdr_profiles.field_profile%TYPE;
port_profile fdr_profiles.port_profile%TYPE;
sup_shell fdr_profiles.supervisor_shell%TYPE;
lvl fdr_profiles.lvl%TYPE;
x varchar2(50) :=null;
BEGIN
testProc(p_user_id => 'abc,def',
p_recordset => v_cursor);
LOOP
FETCH v_cursor INTO
user_id, shell_desc, tran_profile, fld_profile,
port_profile, sup_shell, lvl;
IF v_cursor%NOTFOUND THEN
DBMS_OUTPUT.PUT_LINE('no records');
ELSE
DBMS_OUTPUT.PUT_LINE(user_id || ' | ' || shell_desc|| ' | ' || tran_profile);
END IF;
EXIT WHEN v_cursor%NOTFOUND;
END LOOP;
CLOSE v_cursor;
END;
/