Sqlplus spool to dynamic Log File Name

Source: Internet
Author: User

Sqlplus spool to dynamic log file name through the sqlplus spool function we output the results of routine database O & M to the log file, and sometimes it needs timed output, in order to avoid repeated log file names, the output log file name can be dynamically named. This article provides an example for your reference. Www.2cto.com 1. The script for generating dynamic log files [SQL] robin @ SZDB: ~> More dynamic_logfile_name. SQL -- + ====================================== ===========================+ -- | Filename: dynamic_logfile_name. SQL | -- | Desc: | -- | This is only a sapmle to generate dynamic log file name | -- + ================== ========================================================== = + set termout off echo off verify off set feedback off variable dt VARCHAR2 (13 ); COL dt FORMAT a15 COL report_name MAT a35 begin select TO_CHAR (SYSDATE, 'yyyymmdd _ 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 FEEDBAC K on; UNDEFINE rpt_name EXIT; 2. Test script [SQL] robin @ SZDB: ~> Sqlplus-S scott/tiger @ cnmmbo @ dynamic_logfile_name. SQL robin @ SZDB: ~> Date Fri Mar 15 11:13:04 CST 2013 robin @ SZDB: ~> Sqlplus-S scott/tiger @ cnmmbo @ dynamic_logfile_name. SQL robin @ SZDB: ~> Ls-hltr LS-DYNA *. log-rw-r -- 1 robin oinstall 45 2013-03-15 dynamic_logfile_20130315_1111.log-rw-r -- 1 robin oinstall 45 2013-03-15 intervals 3. describes a. usage of the sqlplus command see: SQL * Plus User's Guide and Reference) b. In the above script, the variable dt is defined to store the system time and date. It is used for the second half of the dynamic log file. c. Use the variable: the value of d and begin end blocks can be assigned by SQL queries in dt mode. Otherwise, the assignment fails. e. Some prompts can be removed by yourself, such as print dt and prompt.

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.