我有以下bash脚本,应该用当前日期调用sqlplus。
#!/bin/bash
DATE='date +%F'
sqlplus -s << EOF1
DB_username/DB_password
set heading off
exec PLSQL_PROCEDURE('$DATE', '-30','someString','/home/outputFolder');
exit
EOF1
exit
但我得到以下错误 - 它肯定不会评估date命令:
BEGIN PLSQL_PROCEDURE('date +%F', '-30', 'someString', '/home/outputFolder'); END;
*
ERROR at line 1:
ORA-01841: (full) year must be between -4713 and +9999, and not be 0
ORA-06512: at "DataBaseName.PLSQL_PROCEDURE", line 19
ORA-06512: at line 1
如何修复它以便它传递当前日期,就像这样?
PLSQL_PROCEDURE('2013-03-14', '-30', 'someString', '/home/outputFolder');
答案 0 :(得分:1)
请改为尝试:
#!/bin/sh
DATE=$(date +%F) # note the $( ) form
sqlplus -s << EOF1
DB_username/DB_password
set heading off
exec PLSQL_PROCEDURE('$DATE', '-30','someString','/home/outputFolder');
exit
EOF1
您应该了解命令替换:$(foo bar)
导致命令'foo'以参数'bar'执行,$(..)
将被<{1}}替换EM>输出。见http://mywiki.wooledge.org/BashFAQ/002