使用shell脚本在sqlplus oracle中调用带有date参数的过程

时间:2015-07-22 05:11:33

标签: oracle shell unix sqlplus

我想使用shell脚本在sqlplus oracle中调用一个过程, 我的程序名是getdate_proc,有两个参数,startdate和enddate。 我想设置startdate = sysdateenddate = sysdate + 5 days

for example :execute getdate_proc(to_date('05/05/2015', 'MM-DD-YYYY'),to_date('05/09/2015','MM-DD-YYYY'))

下面是我的代码:

#!/usr/bin/ksh
sqlplus -s /nolog << EOF
connect scott/tiger
--execute procedure with parameter
execute getdate_proc(to_date(sysdate, 'MM-DD-YYYY'),to_date(sysdate + 5days,'MM-DD-YYYY'))
--set spooling to save in csv
set underline off
SET RECSEP OFF
set verify off
set colsep ','
set linesize 300
set trimspool on
spool /home/user/project/samp.csv
select * from att2;
spool off
set verify off

1 个答案:

答案 0 :(得分:2)

我用这段代码解决了我的问题:

#!/usr/bin/ksh
date1='date'
date1=$(/bin/date --date="$date1" -d "+0 day" +"%F")
date2=$(/bin/date --date="$date1" -d "+4 day" +"%F")
echo $date1
echo $date2
sqlplus -s /nolog << EOF
connect scott/tiger
--execute procedure with parameter
execute attendance(to_date('$date1', 'YYYY-MM-DD'),to_date('$date2','YYYY-MM-DD'))
--set spooling to save in csv
set underline off
SET RECSEP OFF
set verify off
set colsep ','
set linesize 300
set trimspool on
spool /home/user/project/samp.csv
select * from att2;
spool off
set verify off

:)干杯