Solved

Spool file with timestamp

Posted on 2000-05-08
3
1,967 Views
Last Modified: 2008-02-01
Does anyone know how I can append the date onto the end of a spool file? I need to run a script once a week that produces a file that someone else is going to pick up. They want the date appended onto the end of the file name i.e. filename08May00.
0
Comment
Question by:efarquha
3 Comments
 
LVL 3

Accepted Solution

by:
jkstill earned 50 total points
ID: 2789323

When creating a spool file, just grab sysdate, store
into a SQL*Plus variable, and attach it to the file name.

Here's how.

col c_my_file_name noprint new_value u_my_file_name

select
   'my_spool_file_'
   || to_char(sysdate,'mm-dd-yyyy-hh24:mi:ss')
   || '.txt'  c_my_file_name
from dual;

spool &u_my_spool_file

select object_name, object_type
from all_objects;

spool off


In this example, the 'COL' command is used to create a variable
'u_my_spool_file' that will be set by the value of the column that
the C_MY_SPOOL_FILE column is use on.

In this case we selected the literal text 'my_spool_file_', the current
date down to the second, and a suffix of '.txt' from dual.

This will create a variable like 'my_spool_file_05-08-2000-10:10:45.txt',
which is then used to hold the output from the example query on
all_objects.


0
 
LVL 3

Expert Comment

by:mgokman
ID: 2789371
Include this at the beginning of your script:

COL dt NEW_VALUE filedate
SELECT TO_CHAR(sysdate, 'DDMonYY') dt FROM dual;
SPOOL filename&&filedate


0
 

Author Comment

by:efarquha
ID: 2792020
You both answered my question but jkstill got there first. Thanks
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that useā€¦
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now