Linux creates timed tasks and executes SQL at timed intervals

Source: Internet
Author: User
Tags sqlplus

Finally figured out a problem. Linux creates timed tasks and executes SQL on a timed basis, which is divided into two case.

CASE1 SQL statements are small, so write SQL statements directly in the shell script. As follows:

[Email protected] scripts]$Cat add_data.sh
#!/bin/bash

oracle_base=/u01/app/oracle; export Oracle_base
oracle_home= $ORACLE _base/product/11.2.0/db_1; export Oracle_home
oracle_sid=prod; export Oracle_sid
oracle_unqname=prod; export Oracle_unqname
oracle_term=xterm; export Oracle_term
oracle_hostname=ora11g; export Oracle_hostname
path=/usr/sbin: $PATH; export PATH
path= $ORACLE _home/bin: $PATH; export PATH

sqlplus test/test <<eof
Spool/home/oracle/scripts/add_data.log Append--Add spool here in order to take the specific operation of SQL, left as a log
INSERT into test values (sysdate);
commit;
Spool off
exit;

Case2 SQL scripts and then writes SQL scripts in shell scripts. As follows:

[Email protected] scripts]$ cat add_data02.sh

#!/bin/bash

Oracle_base=/u01/app/oracle; Export Oracle_base
Oracle_home= $ORACLE _base/product/11.2.0/db_1; Export Oracle_home
Oracle_sid=prod; Export Oracle_sid
Oracle_unqname=prod; Export Oracle_unqname
Oracle_term=xterm; Export Oracle_term
oracle_hostname=ora11g; Export Oracle_hostname
Path=/usr/sbin: $PATH; Export PATH
Path= $ORACLE _home/bin: $PATH; Export PATH

Sqlplus test/test <<eof
Spool/home/oracle/scripts/add_data02.log Append
@/home/oracle/scripts/add_data.sql---Here add_data.sql is the SQL script to execute
Spool off
Exit

The SQL Script Add_data.sql is as follows:
[Email protected] scripts]$ cat Add_data.sql

INSERT into test values (sysdate+1);
Commit

Linux creates timed tasks and executes SQL at timed intervals

Related Article

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.