ORACLE database comes with DBMS_JOB function can realize the execution of PL /SQL stored procedures, but if the SQL statement is very complicated, SQL statements are many, and often need to change the SQL statement The way of writing, using the method of writing PL /SQL stored procedures and then re-execution will be more cumbersome. Moreover, some UNIX system administrators do not write PL/SQL stored procedures, so I introduced a simple shell program to implement a *.sql file on a UNIX machine with ORACLE SERVER or CLIENT.
First we connect to the destination database on a UNIX machine with ORACLE SERVER or CLIENT installed:
$sqlplus username/password@servie_name
If you can successfully enter SQL> state, And execute a simple SQL statement
SQL> SELECT SYSDATE FROM DUAL;
indicates that the connection is successful, otherwise check if servie_name is correctly defined in /$ORACLE_HOME/network/admin/tnsnames.ora.
Whether /etc/hostname contains the host name of the destination database, etc. (other network checks are not listed here in detail).
Next run the test SQL statement under the scott user: scott_select.sql
SQL> SELECT D.DNAME, E.ENAME, E.JOB, E.HIREDATE FROM EMP E, DEPT D WHERE TO_CHAR(E.HIREDATE, 'YYYY')='1981' AND E.DEPTNO=D.DEPTNO;
Then write a shell file like scott_select.sh in the directory /oracle_backup/bin/Br>
--------------------------------------------- --------------------------- su - oracle -c "sqlplus scott/tiger@servie_name"<<EOF spool /oracle_backup/Log/scott_select.txt; @/oracle_backup/bin/scott_select.sql; spool off; exit; ----------------------------- --------------------------------------------
Description:
Spool statement output the execution result of scott_select.sql statement to /oracle_backup/log/scott_select.txt file
@symbol is execute /oracle_backup/bin/scott_select.sql file
You can store multiple SQL statements such as DML and DDL in the *.sql file to be executed.
Change the attribute of scott_select.sh to 755, you can execute
$chmod 755 /oracle_backup/bin/scott_select.sh
This way, UNIX system administrator (root privileges) You can use the crontab command to add scott_select.sh to the timer operation queue.
Or directly edit the configuration file under OS:
Sun Solaris file /var/spool/cron/crontabs/root Linux file /var/spool/cron/root
Add a line after the root file (meaning: execute scott_select.sh at 4:40 on the 18th of each month)
40 4 18 * * /oracle_backup/bin/scott_select.sh
Timetable In order: minutes (0— 59) hours (0— 23) dates (1— 31) months (1— 12) days of the week (0— 6)
You can combine them according to different needs .
Restart the timing service of the OS to make the newly added task take effect.
Sun Solaris #/etc/rc2.d/S75cron stop #/etc/rc2.d/S75cron start Linux #/etc/rc.d/init.d/crond restart
This way The ORACLE database will periodically execute the scott_select.sql file and output the result to the OS file scott_select.txt.
If we want to write or modify the scott_select.sql file, just edit it.
Today, I have brought the steps of adding static routes for Linux, I hope to help my friends! 1. Add
In daily work or experiment, we often need to clone or migrate the virtual machine. After the migra
Starting today, I officially entered the development of tiny4412. Today I mainly watched the startu
Linux Mint is an Ubuntu-based distribution whose goal is to provide a more complete and immediate ex
A recovery method for accidentally deleting files under Linux
Linux port listener implementation tutorial
CentOS 6.x uses yum to install nginx environment
Introduction to the tens of millions of concurrent HAproxy balanced load systems
Quartz Time Configuration Basic Tutorial
Linux domain name resolution function gethostbyname and getaddrinfo
Usage of $(), $(()), and ${} in Shell
Discussion on fence devices in RHCS
Common operating commands for Linux systems
Windows 10 mobile version 2K flagship information exposure 5.2 inch large screen
Win10 Professional login interface does not have a shutdown button recovery method
Win7 system play famine game error during initialization prompt how to solve?
Win8 start screen program is not working properly?
How Win10 recovers Win8.1 network list
Windows 7 system commonly used shortcut operation method
Setting the menu state of the Win8 Explorer ribbon
What should I do if my notebook runs win8 system too?
Realize network remote unified shutdown with Windows XP system
Win10 fingerprint recognition login Windows hello demo video