Thursday, July 28, 2016

Dynamic File Name in Command Spool

Is it possible to change the spool file name dynamically?

Yes its possible to change the name dynamically. but its depending on the requirement.Here is the sample example how we can add the date string to the file name.

once you know how to add the date string to file name then you can apply the same formula to any others.

we have to take one dummy column to print and will take the date in to that dummy column. see the example below

SQL> column filename new_val filename
SQL> select sysdate filename from dual;

FILENAME
---------
28-JUL-16

SQL> spool &filename
SQL> select sysdate from dual;

SYSDATE
---------
28-JUL-16

SQL> spool off;
SQL>
once its done ,you can check the file in the same folder from where you have login to oracle.
or you can specify the path to generate the file.

for this case all the files will generate with the extinction is ".LST". example : "28-JUL-16.LST"


No comments:

Post a Comment

Thanks for giving comments!!