使用Shell脚本调用存储过程

时间:2012-03-16 15:51:18

标签: oracle stored-procedures sqlplus

你能帮帮我吗? 如何使用sqlplus从shell脚本连接数据库Oracle? 你能做一个调用存储过程的shell脚本的例子吗?

谢谢。

2 个答案:

答案 0 :(得分:1)

创建一个xxxx.sql文件并执行它:

set serveroutput on;
execute STORED_PROCEDURE;
set serveroutput off;
exit

您需要一种方法来执行脚本,我在基于* nix的系统上使用CRON。我的脚本看起来像这样

#!/bin/sh
# This short shell script calls the XXXX Stored Procedure
# drive.
PATH=$PATH:/opt/oracle/local/bin:/usr/local/bin
export ORACLE_SID=XXXX;   
export ORAENV_ASK=NO;      
export TWO_TASK=XXXXXXXXX;    
. /usr/local/bin/oraenv
sqlplus USERID/PASSWPRD @SQL_Script_to_call_stored_Proceudre.sql
exit 

答案 1 :(得分:0)

以下是一个例子:

创建一个sh文件“callProcedureFromBash.sh”

#!/bin/bash      this is a comment

#if you can access sqlplus already, you don't need following 2 lines
export ORACLE_HOME = /efs/dist/oracledb/client/10G/exec
export PATH=$PATH:$ORACLE_HOME/bin

sqlplus "userid/password@(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP) (HOST = WWW.YOURHOST.COM) (PORT = 12345) (CONNECT_DATA = (SID = HXZ524))))" <<END

DECLARE
    a int;
BEGIN
    packagename.Procedurename(a);
END;
/
commit;