I'm not sure I follow your code - certainly the constructs are not valid
SQL> declare
2 type ty_test(emp scott.emp%rowtype,dept scott.dept%rowtype);
3 begin
4 null;
5 end;
6 /
type ty_test(emp scott.emp%rowtype,dept scott.dept%rowtype);
*
ERROR at line 2:
ORA-06550: line 2, column 13:
PLS-00103: Encountered the symbol "(" when expecting one of the following:
; is authid as force under accessible
ORA-06550: line 3, column 1:
PLS-00103: Encountered the symbol "BEGIN"
ORA-06550: line 5, column 4:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
end not pragma final instantiable order overriding static
member constructor map
If you want to return both EMP and DEPT data, then you would return 2 collections to the calling environments. However, if your really saying that these are just examples, and that we could be passing an arbitrary list of tables, then we're into dynamic SQL territory. If the number and/or name of columns that are coming back from a cursor are not known until run time, then this will require dynamic SQL. Here's an example of a script that demonstrates the various facilities in DBMS_SQL to see
- what columns are in the query
- what data types they are
- how to fetch them iteratively
SQL> set serverout on
SQL> declare
2 l_query varchar2(32767) := 'select * from scott.dept';
3
4 l_theCursor integer default dbms_sql.open_cursor;
5 l_columnValue varchar2(4000);
6 l_status integer;
7 l_descTbl dbms_sql.desc_tab;
8 l_colCnt number;
9 n number := 0;
10 procedure p(msg varchar2) is
11 l varchar2(4000) := msg;
12 begin
13 while length(l) > 0 loop
14 dbms_output.put_line(substr(l,1,80));
15 l := substr(l,81);
16 end loop;
17 end;
18 begin
19 dbms_sql.parse( l_theCursor, l_query, dbms_sql.native );
20 --
21 -- how to get the columns from the query
22 --
23 dbms_sql.describe_columns( l_theCursor, l_colCnt, l_descTbl );
24
25 --
26 -- how to define return values from the cursor once we fetch from it
27 --
28 for i in 1 .. l_colCnt loop
29 dbms_sql.define_column(l_theCursor, i, l_columnValue, 4000);
30 end loop;
31
32 l_status := dbms_sql.execute(l_theCursor);
33
34 --
35 -- how to fetch each column and each row
36 --
37 while ( dbms_sql.fetch_rows(l_theCursor) > 0 ) loop
38 for i in 1 .. l_colCnt loop
39 dbms_sql.column_value( l_theCursor, i, l_columnValue );
40 p( rpad( l_descTbl(i).col_name, 30 )
41 || ': ' ||
42 l_columnValue );
43 end loop;
44 dbms_output.put_line( '-----------------' );
45 n := n + 1;
46 end loop;
47 if n = 0 then
48 dbms_output.put_line( chr(10)||'No data found '||chr(10) );
49 end if;
50 end;
51 /
DEPTNO : 10
DNAME : ACCOUNTING
LOC : NEW YORK
-----------------
DEPTNO : 20
DNAME : RESEARCH
LOC : DALLAS
-----------------
DEPTNO : 30
DNAME : SALES
LOC : CHICAGO
-----------------
DEPTNO : 40
DNAME : OPERATIONS
LOC : BOSTON
-----------------