Creating spool file dynamically [message #472417] |
Fri, 20 August 2010 08:17 |
Aju
Messages: 94 Registered: October 2004
|
Member |
|
|
Can you please guide how to creat a file in a folder based on todays date. More precisely, i need to know how to define a variable in sqlplus and assign a value to it.
Here is the code below. The code gets executed without creating a spool file.
DEFINE _DATE = replace('C:\_sysdate_\EU001.csv', '_sysdate_', TO_CHAR(SYSDATE, 'DD-MON-YYYY'))
spool _DATE
set serveroutput on size 100000
select * from dual;
spool off
Thanks
|
|
|
|
|
Re: Creating spool file dynamically [message #472425 is a reply to message #472417] |
Fri, 20 August 2010 08:29 |
Aju
Messages: 94 Registered: October 2004
|
Member |
|
|
I have tweaked tour code a litle but still unable to get the result.
let me be clear if i am not. My goal is to create a spool file in C:\20-AUG-2010
SQL> set termout off
SQL> col dt new_value dt
SQL> select replace('C:\_sysdate_\EU001.csv', '_sysdate_', TO_CHAR(SYSDATE, 'DD-MON-YYYY')) dt from
dual;
DT
--------------------------------------------------------------------------------
C:\20-AUG-2010\EU001.csv
SQL> set termout on
SQL> spool _dt
SQL> select * from dual;
D
-
X
SQL> spool off
SQL>
|
|
|
|
|
Re: Creating spool file dynamically [message #472443 is a reply to message #472428] |
Fri, 20 August 2010 10:00 |
Aju
Messages: 94 Registered: October 2004
|
Member |
|
|
I am sorry that accidentally i submitted the same twice. I am not sure if you are refering to the foramting of the code, i have done the formating. Please let me know if i have missed any.
SET termout off
COL dt new_value dt
SELECT TO_CHAR (SYSDATE, 'YYYYMMDDHH24MISS') dt
FROM DUAL;
SET termout on
SPOOL file_&dt
SELECT *
FROM DUAL;
SPOOL off
|
|
|
|
Re: Creating spool file dynamically [message #472445 is a reply to message #472444] |
Fri, 20 August 2010 10:09 |
Aju
Messages: 94 Registered: October 2004
|
Member |
|
|
I am sorry, please ignore the earlier post of my code . Actually I need the spool file to be created at the location C:\20-Aug-2010.
Here is the code
SET termout off
COL dt new_value dt
SELECT REPLACE ('C:\_sysdate_\EU001.csv',
'_sysdate_',
TO_CHAR (SYSDATE, 'DD-MON-YYYY')
) dt
FROM DUAL;
SET termout on
SPOOL _&dt
SELECT *
FROM DUAL;
SPOOL off
And here is the output
SQL> SPOOL off
SQL> SET termout off
SQL> COL dt new_value dt
SQL> SELECT REPLACE ('C:\_sysdate_\EU001.csv',
2 '_sysdate_',
3 TO_CHAR (SYSDATE, 'DD-MON-YYYY')
4 ) dt
5 FROM DUAL;
DT
------------------------------------------------------------------
C:\20-AUG-2010\EU001.csv
SQL> SET termout on
SQL> SPOOL _&dt
SP2-0332: Cannot create spool file.
SQL> SELECT *
2 FROM DUAL;
D
-
X
|
|
|
|
|
|
|
|
Re: Creating spool file dynamically [message #472454 is a reply to message #472450] |
Fri, 20 August 2010 10:35 |
Aju
Messages: 94 Registered: October 2004
|
Member |
|
|
Thank you very much for your time. This is done
SQL> SET termout off
SQL> COL dt new_value dt
SQL> SELECT REPLACE ('C:\_sysdate_\EU001.csv',
2 '_sysdate_',
3 TO_CHAR (SYSDATE, 'DD-MON-YYYY')
4 ) dt
5 FROM DUAL;
DT
--------------------------------------------------------------------------------
C:\20-AUG-2010\EU001.csv
SQL> SET termout on
SQL> SPOOL &dt
SQL> SELECT *
2 FROM DUAL;
D
-
X
SQL> SPOOL off
|
|
|