Linux timed export SQL query result file

Source: Internet
Author: User

If you want to generate a TXT file for SQL query results on the server side.

The general idea is:

1. Create a SQL script that is a TXT file everywhere.

SetARRAYSIZE - --number of records sent from the database to the client at one timeSetLinesize - --number of characters in a rowSETPAGESIZE0 --Set without pagingSetTimingoff --turn off show SQL execution TimeSetHeadingoff --column names for each row are not displayedSetFeedbackoff --Echo the number of record bars processed by this SQL command, default to onSETTrimout on --Remove trailing spaces per line of standard output, default to OFFSetTrimspool on --Remove redirect (spool) output trailing spaces per line, default to OFFSetTermoutoff --displays the execution result of the command in the script, which is on by defaultdefine R_filename=&1 --define the export file path and file nameSpool&R_filename;SelectEmpno||','||Ename fromEmp;spooloff;

2. Create a shell script to invoke the well-written SQL script.

#! /bin/Bashstart_time=`Date+%y%m%d%h%m%S 'Echo$START _timetimestamp=`Date+%y%m%d%h%m%S ' Db_user="Apps/[email protected]"Path_file= $HOME/sql/Tt$timestampsql_file= $HOME/sql/Tt.sqlEcho 'Start Time is:'$TIMESTAMPEcho 'SQL file is:'$SQL _fileEcho 'Out file is:'$PATH _filesqlplus-S $DB _user <<eof@ $SQL _file $PATH _fileQuiteofend_time=`Date+%y%m%d%h%m%S 'Echo$END _time

3. You can create a Linux timed task, which is timed to invoke the shell script as above.

1) Create a file for the scheduled Task list first, Oraclecron

  

#分 the day and month the full path of the moon command
#这条命令表示每个15分钟调用一次/home/oracle/myshell/ttt,0 * ** */home/oracle/ Myshell/ttt

2) Add this scheduled task to the system crontab list

Crontab Oraclecron

3) You can view the system Crontab task with the following command, if you see the task you added in the Oraclecron file is OK.

Crontab-l

4. After adding success from a timed task, the shell script created in 2 is dropped every time the whole clock system is added, and 2 of the shell script calls 1 SQL script.

A file is eventually generated on the Oracle server.

Linux timed export SQL query result file

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.