问题
The dynamic request looks like this:
request := 'select * from ' || param_table_name || ' where ' || column_name_list;
Then I do:
open cur1 for request;
The exact type of record fetched via cur1
isn't known until runtime, because it should impose no restrictions on whatever table this procedure is applied to. But then, how do I iterate through what the query returns?
回答1:
PL/SQL cursors cannot work with columns that aren't known a compile time.
To only way to work with fully dynamic queries in PL/SQL is by using the PL/SQL package DBMS_SQL
.
Update:
Oracle has a comprehensive description of the DBMS_SQL package with many examples.
来源:https://stackoverflow.com/questions/6478419/oracle-dynamic-sql-select-query-record-type