0

我有以下 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');
4

1 回答 1

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' 执行$(..)并将被输出替换。见http://mywiki.wooledge.org/BashFAQ/002

于 2013-03-14T22:33:09.777 回答