Solved

Spool file with timestamp

Posted on 2000-05-08
3
2,381 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 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
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
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

762 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