无法通过 shell(ksh) 进行假脱机

无法通过 shell(ksh) 进行假脱机

我编写了一个 shell 脚本,其中定义了变量:Last_Monthlast_date并且first_date我尝试从 shell 执行以下 sql:

/app/oracle/product/10.2.0/bin/sqlplus -s user_name/passwd @effective_date.sql

内容effective_date.sql

set heading off
set feedback off
set verify off
set pagesize 50000
set trimspool on
set wrap off
set newpage none
set linesize 2000

spool /home/dir/file_${Last_Month};

select * from table_1
where effective_date between to_date("$first_date",'dd-mm-yyyy') and to_date("$last_date",'dd-mm-yyyy');

spool off;
exit;

但在执行 shell 时,我收到以下错误:

SP2-0332: Cannot create spool file.
where effective_date between to_date("$first_date",'dd-mm-yyyy') and to_date("$last_date",'dd-mm-yyyy')
                                                                             *
ERROR at line 2:
ORA-00904: "$last_date": invalid identifier


not spooling currently

有什么帮助吗?

答案1

sqlplus应该对 shell 变量使用不同的方法。你的命令应该变成:

/app/oracle/product/10.2.0/bin/sqlplus -s user_name/passwd @effective_date.sql "$Last_Month" "$first_date" "$last_date" 

你的sql脚本应该是:

set heading off
set feedback off
set verify off
set pagesize 50000
set trimspool on
set wrap off
set newpage none
set linesize 2000

spool /home/dir/file_'&1';

select * from table_1
where effective_date between to_date('&2','dd-mm-yyyy') and to_date('&3','dd-mm-yyyy');

spool off;
exit;

相关内容