有个存储过程 chk 只返回一个NUMBER类型参数但是我在写SHELL的时候 怎么接受这个存储过程的参数啊 MY.SH#! /bin/bash
tb_name=$1sqlplus -S gbdb/gbdb@orcl_63 <<EOF
-- 函数
create or replace function chk_f
return number is
v_cnt number;
begin
select count(*) into v_cnt from $tb_name;
return v_cnt;
end ;
/-- 过程
create or replace procedure chk_p(
cnt out number
)is
begin
select count(*) into cnt from $tb_name;
end ;
/
exit;
EOF请问关于函数和过程 应该怎么去接返回的参数
tb_name=$1sqlplus -S gbdb/gbdb@orcl_63 <<EOF
-- 函数
create or replace function chk_f
return number is
v_cnt number;
begin
select count(*) into v_cnt from $tb_name;
return v_cnt;
end ;
/-- 过程
create or replace procedure chk_p(
cnt out number
)is
begin
select count(*) into cnt from $tb_name;
end ;
/
exit;
EOF请问关于函数和过程 应该怎么去接返回的参数
#下面的代码是对于从oracle的sqlplus返回变量值给shell的例子
output=`sqlplus -s unitele/lemontea << EOF
set heading off feedback off verify off
drop function test_get_param_value_p;
CREATE OR REPLACE function test_get_param_value_p
(
is_citycode in varchar2
)
return varchar2
is
on_value varchar2(100);
begin
on_value :='100000';
dbms_output.put_line(on_value);
dbms_output.put_line(is_citycode);
return on_value;
end;
/
select test_get_param_value_p('501') from dual;
exit
EOF
`
echo "Oracle的输出变量值:"$output
sql脚本模板
先编辑一个mysql.sql文件,内容如下:
------------
var nret number;
execute :nret := 0;--初始化
call myproc(in_code,:nret)--执行存储过程,in_code会被替换掉
/
select 'retcode[' || :nret || ']retcode' from dual--显示结果
/
quit;
-------------
再编辑SHELL脚本mysh.sh,内容如下
-------------
#./mysh.sh 123
cd /home/myshell
sed "s/in_code/$1/" mysql.sql > mysql01.sql
#根据sql脚本模板生成实际脚本
sqlplus usr/pwd@db result$1.txt
#执行sql脚本并把结果输入result$1.txt
echo ok!
-------------
在LINUX下执行./mysh.sh 123,生成result123.txt,myproc输出参数在'retcode['和']retcode'之间。