How to create a dynamic spool file for SQLPLUS

De Notas pessoais





The example below will show you how to create a new log file for each execution of the script:

column vpath old_value new_vpath
column dt    old_value new_dt
column ext   old_value new_ext
select 'F:\DBA_Scripts\logs\' vpath,to_char(sysdate,'yyyymmdd_hh24miss') dt, '_Atualiza.log' ext from dual;
spool &new_vpath&new_dt&new_ext
select sysdate from dual;
quit;

For the example above, each time the script runs a new log will be created as follows:

F:\DBA_Scripts\logs\20111219_161344_Atualiza.log
F:\DBA_Scripts\logs\20111219_161343_Atualiza.log
F:\DBA_Scripts\logs\20111219_145400_Atualiza.log


Ferramentas pessoais
Imprimir/exportar

contador de visitas