Thursday, February 4, 2021

Oracle Spool

Here is how to create a log file for your script:
SET echo ON
SET feedback ON
SET SERVEROUTPUT ON
SET linesize 500
COL spoolname new_value filename
SELECT TO_CHAR(systimestamp, 'YYYY_MM_DD_HH24_MI_') || 
	(SELECT SYS_CONTEXT ('userenv', 'current_schema') FROM  dual) || 
	'_log_name.log' AS spoolname FROM dual;
SPOOL &filename

-- start main SQL script
INSERT INTO my_table (total) VALUES (25);
-- end main SQL script

SPOOL OFF
EXIT;
This will create a log file with name like this 2019_11_11_23_00_schema_name_log_name.log.