I have the below code, which works fine.
SET SERVEROUTPUT ON;
DECLARE
cols CLOB;
BEGIN
SELECT
LISTAGG('"'
|| column_name
|| '"', ',') WITHIN GROUP(
ORDER BY
column_name
)
INTO cols
FROM
all_tab_columns
WHERE
lower(table_name) = 'd_dialler_brut'
AND column_name LIKE 'REASON%';
dbms_output.put_line(cols);
END;
However, if I try the below code, it throws the below error
Error report - ORA-00905: missing keyword ORA-06512: at line 20 00905. 00000 - "missing keyword"
SET SERVEROUTPUT ON;
DECLARE
cols CLOB;
vstr_cols CLOB;
BEGIN
vstr_cols := q'[
SELECT
LISTAGG('"'
|| column_name
|| '"', ',') WITHIN GROUP(
ORDER BY
column_name
)
INTO cols
FROM
all_tab_columns
WHERE
lower(table_name) = 'd_dialler_brut'
AND column_name LIKE 'REASON%']'
;
EXECUTE IMMEDIATE ( vstr_cols );
dbms_output.put_line(cols);
END;
What's wrong in the second code? How can I avoid the error?