On the move:

I'm currently moving the following to their own blogs: Unix, HTML for Blogs, Perl & Java.
The links are on the left side.

Thursday, July 3, 2008

Insert Date and/or Time Into Spool Name


To generate a report with a date in the filename:

Example: Tblinfo-20080703-1044.Txt

Define Spool name as
  1. Some identifying report name
  2. &variable date name can be smashed up next to it with no concatenation symbols
  3. to put something behind it (like a file extension), use a period. I have '..txt'. (The first is a concatenation symbol; the second is the one normally seen between the filename and extension.)
------------------------------------------------------------------
-- Set Terminal off so the first query doesn't display.
-- Select to get the date/time from the system, and
-- then set Terminal back on. Use New_Value to create a variable.
------------------------------------------------------------------

Set Term Off

Column ReportDate New_Value xRptDate

Select To_Char(Sysdate,'yyyymmdd-hh24mi') ReportDate
From Dual;

Set Term On

------------------------------------------------------------------
-- Run the report
------------------------------------------------------------------

Spool Tblinfo-&xRptDate..Txt

Select EmpNo, EName, Sal, Deptno, Mgr, Job
From Emp;

Spool Off

------------------------------------------------------------------
-- Optionally, tell them the new name of the report.
------------------------------------------------------------------

Prompt
Prompt Your report has been spooled to Tblinfo-&xRptDate..Txt

No comments:

Post a Comment