I would like to display results of dynamic sql based on antoher sql, but get error message. My code:
DECLARE
sql_qry VARCHAR2(1000) := NULL;
TYPE results IS
TABLE OF all_tab_columns%rowtype;
results_tbl results;
BEGIN
FOR i IN (
SELECT
*
FROM
all_tab_columns
WHERE
owner = 'OWNER_XYZ'
AND upper(column_name) LIKE '%COLUMN_XYZ%'
ORDER BY
table_name,
column_name
) LOOP
sql_qry := ' SELECT DISTINCT '
|| i.column_name
|| ' as column_name '
|| ' FROM '
|| i.owner
|| '.'
|| i.table_name
|| ' WHERE SUBSTR('
|| i.column_name
|| ',1,1) = ''Y''';
EXECUTE IMMEDIATE sql_qry BULK COLLECT
INTO results_tbl;
dbms_output.put_line(results_tbl);
END LOOP;
END;
I get the error message:
PLS-00306: wrong number or types of arguments in call to 'PUT_LINE'
In fact I need the results of all queries with an union between them like that [1] [1]: https://i.sstatic.net/llxzr.png
dbms_output.put_line(results_tbl.column_name);resultsis defined usingall_tab_columns, so the bulk collect into won't work anyway (it just isn't getting that far at the moment); you are only selecting a single column from the target tables, so the collection would need to reflect that column and its data type. Yourput_lineis also referring to the whole collection, not one record from it; soresults_tbl(1).column_namewould be valid, though you'd actually need to loop and use an index variable so see all values.