I have a SQL script that will be used to make changes in the database. For audit and traceability reasons, I want the script to generate an output file name based on the DBNAME and timestamp.
db_test=> select 'script_output-' || :'DBNAME' || '-' || to_char(now(),'yyyymmdd-HH24MISS') || '.txt' as spoolfile; spoolfile -------------------------------------------- script_output-db_test-20190718-163936.txt However, when I try to assign the query result to the \out operator I get the following
db_test=> \out select 'script_output-' || :'DBNAME' || '-' || to_char(now(),'yyyymmdd-HH24MISS') || '.txt' \out: extra argument "script_output-" ignored \out: extra argument "||" ignored \out: extra argument ":'DBNAME'" ignored \out: extra argument "||" ignored \out: extra argument "-" ignored \out: extra argument "||" ignored \out: extra argument "to_char(now(),yyyymmdd-HH24MISS)" ignored \out: extra argument "||" ignored \out: extra argument ".txt" ignored The output file actually created was named select
SDV184022L:~ myuser$ ls -la Downloads/DB-Install/sele* -rw-r--r-- 1 myuser myuser 0B Jul 18 11:42 Downloads/DB-Install/select Based on these results and lots of searching, I'm going to assume this is not possible so does anyone have an alternative way to accomplish generating a dynamic filename for the output directive?