Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Spool file with timestamp

Posted on 2000-05-08
3
Medium Priority
?
2,800 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

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…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

610 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