I am working with Oracle 11gR2 PL/SQL tables (nested table), but just getting a little confused on whether the following two approaches are achieving the same result, i.e.:
Assuming I have defined the following TYPE:
type member_nos_type is table of varchar2(32000);
and the following sample table definition/data:
table: my_members
id number not null,
membernos varchar2(30) not null,
first_nm varchar2(255),
surname varchar2(255)
Sample data in table my_members:
1 111111 Joe Smith
2 222222 Sam Smith
3 333333 Jane Smith
4 444444 Jason Smith
5 555555 Joel Smith
then within a procedure, I have the following code:
procedure a1 (p_param1 in varchar2) is
v_member_list member_nos_type;
begin
if p_param1 = 'BASKETBALL' then
v_member_list := member_nos_type ('222222','444444');
end if;
end;
----------------------------
procedure b2 (p_param1 in varchar2) is
v_member_list member_nos_type;
begin
if p_param1 = 'BASKETBALL' then
v_member_list := member_nos_type (
SELECT LISTAGG(membernos, ',') WITHIN GROUP (ORDER BY membernos)
FROM my_members
WHERE id in (2,4));
end if;
end;
Based on procedure a1 and procedure b2 above, is the end result a table of member numbers of type varchar2 ?
Update
How can I return a TRUE nested table based on my membernos column data in my my_members table?
a1makes true nested table type, while second procedure uses LISTAGG which returns one string, just values are separated by comma. - Oto Shavadze