shell shell脚本与oracle

shell shell脚本与oracle

我试图将 unix 变量替换为 select 语句,但出现以下错误。我做错了什么?

sqlplus  "/ as sysdba" << EOF
spool /home/oracle/l.log

archive log list;
exit;
EOF

Adest=`cat  /home/oracle/l.log |head -4|tail -1|awk '{print $3}`
sqlplus "/ as sysdba" << EOF
spool /home/oracle/register.lst
select 'alter database register logfile '||''''||$Adest||'/1_'||sequence#||'_915925946.dbf'||'''' from v\$archived_log where applied='NO';
@ /home/oracle/register.lst
exit;
EOF

Error Log:-
SQL> select 'alter database register logfile '||''''||||'/1_'||sequence#||'_915925946.dbf'||'''' from v$archived_log where applied='NO';
select 'alter database register logfile '||''''||||'/1_'||sequence#||'_915925946.dbf'||'''' from v$archived_log where applied='NO'
                                                 *
ERROR at line 1:
ORA-00936: missing expression 


SQL> @ /home/oracle/register.lst
SQL> exit;


cat  /home/oracle/l.log|head -4|tail -1|awk {'print $3'}
/u01/app/oracle/DG1_ARCH

答案1

添加以下内容后工作正常

选择'更改数据库注册日志文件'''||'$Adest'||'/1_'||sequence#||'_915925946.dbf'||''';'来自v\$archived_log,其中apply='NO';

感谢您的建议和帮助!!!

答案2

感谢您的帮助,下面工作正常。

select 'alter database register logfile '''||'$Adest'||'/1_'||sequence#||'_915925946.dbf'||''';' from v\$archived_log where applied='NO';  

SQL> 
alter database register logfile '/u01/app/oracle/DG1_ARCH/1_452_915925946.dbf';
alter database register logfile '/u01/app/oracle/DG1_ARCH/1_453_915925946.dbf';

相关内容