将日期参数从Unix传递到Oracle存储过程

时间:2013-09-12 02:05:04

标签: sql oracle shell unix

我正在编写一个Unix shell脚本来调用带有日期作为输入参数的Oracle存储过程,但是我收到以下错误。请帮助我如何将日期参数从Unix传递给Oracle存储过程。

我需要传递给程序的预期日期格式是:

Start Date:       2013-09-12 00:00
End Date  :       2013-09-04 00:00

错误我在执行Unix脚本时得到的结果:

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
     SQL> SP2-0552: Bind variable "00" not declared.
     SQL> SP2-0734: unknown command beginning "echo " C3 ..." - rest of line ignored.
     SQL> SP2-0734: unknown command beginning "echo "####..." - rest of line ignored.

我的Unix shell脚本源:

date1='date'
date1=$(/bin/date --date="$date1" -d "+0 day" +"%F")
date1+=" 00:00"
date2=$(/bin/date --date="$date1" -d "-8 day" +"%F")
date2+=" 00:00"
echo "Report Period"
echo "Start Date:       "$date1
echo "End Date  :       "$date2
sqlplus preprdsm/PREPRDSM@pssm <<EOF
execute C3_REPORT($date1,$date2)
echo " C3 REPORT Executed Successfully "

我的Oracle存储过程输入是:

create or replace
PROCEDURE C3_REPORT(
START_DATE IN date,
END_DATE IN date)
IS
emesg VARCHAR2(250); 

1 个答案:

答案 0 :(得分:2)

您必须将日期值括在引号中,以便Oracle看到引号。

sqlplus preprdsm/PREPRDSM@pssm <<EOF
execute C3_REPORT('$date1', '$date2')
echo "C3 report Executed Successfully"
EOF

假设您的NLS设置与日期格式匹配。