Linux creates timed tasks and executes sql regularly

Finally figured out a problem. Linux creates timed tasks and executes sql regularly, which is divided into two cases.

Case1 has fewer sql statements, so write sql statements directly in the shell script. as follows:

[oracle@Oracle11g 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  --此处添加spool 为了取到sql的具体操作,留作日志
insert into test values(sysdate);
commit;
spool off
exit;

case2 has many sql statements, so the sql script is rearranged, and then the sql script is written in the shell script. as follows:

[oracle@Oracle11g 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      ---此处 add_data.sql 就是所要执行的sql脚本
spool off
exit;

sql脚本add_data.sql 如下:
[oracle@Oracle11g scripts]$ cat add_data.sql  

insert into test values(sysdate+1);  
commit;

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325843920&siteId=291194637