Sqlplusspool to dynamic Log File Name

Source: Internet
Author: User
Through the SQL plus spool function, we output the daily O & M results of the database to the log file, and sometimes it needs timed output. To avoid repeated log file names, we can

Through the SQL plus spool function, we output the daily O & M results of the database to the log file, and sometimes it needs timed output. To avoid repeated log file names, we can

Through the SQL plus spool function, we output the daily O & M results of the database to the log file, and sometimes it needs to be output regularly to avoid repeated log file names ,, the output log file name can be dynamically named. This article provides an example for your reference.

1. Generate a dynamic Log File Script

Robin @ SZDB: ~> More dynamic_logfile_name. SQL
-- + = =====================================+
-- | Filename: dynamic_logfile_name. SQL |
-- | Desc: |
-- | This is only a sapmle to generate dynamic log file name |
-- | Author: Robinson |
-- | Blog: |
-- + = =====================================+
SET TERMOUT OFF ECHO OFF VERIFY OFF
SET FEEDBACK OFF
VARIABLE dt VARCHAR2 (13 );
COL dt FORMAT a15
COL report_name FORMAT a35

BEGIN
SELECT TO_CHAR (SYSDATE, 'yyyymmd_hh24mi ') INTO: dt from dual;
END;
/

PRINT dt;
COL report_name NEW_VALUE rpt_name

SELECT 'dynamic _ logfile _ '|: dt |'. log' AS report_name from dual;

PROMPT "variable rpt_name value is & rpt_name"
SPOOL & rpt_name
Alter session set nls_date_format = 'yyyymmdd hh24: mi: ss ';

Select sysdate from dual;

Spool off;
Set termout on echo on verify on;
Set feedback on;
UNDEFINE rpt_name
EXIT;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.