?
Solved

Spool file with timestamp

Posted on 2000-05-08
3
Medium Priority
?
2,643 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Accepted Solution

by:
jkstill earned 200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
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 shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

770 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