oracle 使用 Shell 脚本调用存储过程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9740462/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 04:03:36  来源:igfitidea点击:

Call stored procedure with Shell Script

oraclestored-proceduressqlplus

提问by Raffaele

Can you help me? How to connect to database Oracle from shell script using sqlplus? Can you do an example of shell script that call a stored procedure??

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

Thank you.

谢谢你。

回答by ProfessionalAmateur

Create a xxxx.sql file and execute it like this:

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

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

You will need a way to execute your script, I use CRON on *nix based systems. My script looks something like this

您将需要一种执行脚本的方法,我在基于 *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 

回答by Harshil

Here's an example:

下面是一个例子:

create an sh file "callProcedureFromBash.sh"

创建一个 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;