Unix Shell_Shell调用SQLPlus简介(案例)

时间:2014-06-24 09:39:16   收藏:0   阅读:603

2014-06-20 BaoXinjian

bubuko.com,布布扣一、摘要


如果在Oracle EBS中开发Unix Shell,必定会涉及到在Shell中调用PLSQL,在Shell调用PLSQL一般是通过SQLPlus这个工具

关于SQLPlus需明白SQLPlus的登录方式和常用命令,具体的在另文介绍SQLPlus的用法

1. SQLPlus的登录方式

sqlplus [ [<option>] [<logon>] [<start>] ]
           <option> 为: [-C <version>] [-L] [-M "<options>"] [-R <level>] [-S]

2. 登录SQLPlus的基本命令

3. SQLPlus语法

语法结构与PLSQL基本一致,略过

 

bubuko.com,布布扣二、案例


1. 最简单Shell调用SQLPlus的方法

Step1. 代码

1 #!/bin/bash
2 sqlplus -S /nolog > result.log <<EOF
3 set heading off feedback off pagesize 0 verify off echo off
4 conn apps/apps
5 insert into bxj_sqlplus_test values (sysdate, bxjsqlplus1.sh, null);
6 exit
7 EOF

Step2. 执行

>. ./bxjshellsql1.sh

Step3. 结果

bubuko.com,布布扣

 

2.1 把SQLPlus中的值传递给Shell方法一

Step1. 代码

 1 #!/bin/bash
 2 VALUE=`sqlplus -S /nolog <<EOF
 3 set heading off feedback off pagesize 0 verify off echo off numwidth 4
 4 conn apps/apps
 5 select count(*) from bxj_sqlplus_test;
 6 exit
 7 EOF`
 8 if [ "$VALUE" -gt 0 ]; then
 9   echo "The number of rows is $VALUE."
10   exit 0
11 else
12   echo "There is no row in the table."
13 fi

Step2. 执行

>. ./bxjshellsql2.sh

Step3. 结果

bubuko.com,布布扣

2.2 把SQL Plus中的值传递给Shell方法二

Step1. 代码

 1 #!/bin/bash
 2 sqlplus -S /nolog > result.log <<EOF
 3 set heading off feedback off pagesize 0 verify off echo off numwidth 4
 4 conn apps/apps
 5 col coun new_value v_coun
 6 select count(*) coun from bxj_sqlplus_test;
 7 exit v_coun
 8 EOF
 9 VALUE="$?"
10 echo "The number of rows is $VALUE."

Step2. 执行

>. ./bxjshellsql3.sh

Step3. 结果

bubuko.com,布布扣

 

3. 把Shell中的值传递给SQLPlus

Step1.  代码

1 #!/bin/bash
2 COMMENTS="$1"
3 sqlplus -S apps/apps <<EOF
4 insert into bxj_sqlplus_test values (sysdate, bxjsqlplus4.sh, $COMMENTS);
5 exit
6 EOF

Step2. 执行

>. ./bxjshellsql4.sh

Step3. 结果

bubuko.com,布布扣

 

 ********************作者: 鲍新建********************

 bubuko.com,布布扣

 

 参考: 网络资料http://www.blogjava.net/xzclog/archive/2010/04/01/317151.html

Unix Shell_Shell调用SQLPlus简介(案例),布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!