Calling or executing SQL, RMAN, etc. in Linux / Unix shell scripts provides great convenience for automated jobs and multiple repeated executions, so Oracle / Linux shell
Related work is also one of the essential skills of DBA. This article gives examples for Linux / Unix shell scripts calling sql, rman scripts.
First, call sql, rman script by shell script
[python] view plain copy print?
1.shell script calls sql script
#First edit the sql file
[email protected]: ~> more dept.sql
connect scott / tiger
spool /tmp/dept.lst
set linesize 100 pagesize 80
select * from dept;
spool off;
exit;
#Edit the shell script file and call the SQL script within the shell script
[email protected]: ~> more get_dept.sh
#! / bin / bash
# set environment variable
if [-f ~ / .bashrc]; then
. ~ / .bashrc
fi
export ORACLE_SID = CNMMBO
sqlplus -S / nolog @ / users / oracle / dept.sql #Note the method of executing the SQL script here -S means to execute in silent mode
exit
Second, embed SQL statements and rman into shell scripts
[python] view plain copy print?
1.Embed SQL statements directly into shell scripts
[email protected]: ~> more get_dept_2.sh
#! / bin / bash
# Author: Robinson Cheng
# Blog: http://blog.csdn.net/robinson_0612
# set environment variable
if [-f ~ / .bashrc]; then
. ~ / .bashrc
fi
export ORACLE_SID = CNMMBO
sqlplus -S / nolog << EOF #EOF This means that when EOF is encountered during input, the entire SQL script is entered
connect scott / tiger
spool /tmp/dept.lst
set linesize 100 pagesize 80
select * from dept;
spool off;
exit; #Exit the sqlplus environment
EOF
exit #Launch shell script
#Grant script execution permissions
[email protected]: ~> chmod u + x get_dept_2.sh
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.