暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Oracle 关于show error 'PLS-00103: 遇到符号 “_” 时,期望以下之一'?

askTom 2017-08-28
738

问题描述

嗨,克里斯
当我解决Oracle DataGuard物理备用数据库关于GAP的问题时,由于大多数归档日志不存在于动态性能视图 'v $ archived_log '中,并且也存在于操作系统中,因此我需要手动注册这些归档日志,例如 'alter database register logfile'/u01/oradata/archivelog/1_90384 _850739945.dbf';'并且一个接一个地注册归档日志非常困难,以至于我决定使用PL/SQL代码来完成。
现在,我的查询步骤如下,
SYS@standby> set linesize 300
SYS@standby> set pagesize 300
SYS@standby> col name for a60
SYS@standby> select name,sequence#,applied from v$archived_log order by 2;

NAME                                                          SEQUENCE# APPLIED
------------------------------------------------------------ ---------- ------------------
/u01/oradata/archivelog/1_90384_850739945.dbf                     90384 NO
/u01/oradata/archivelog/1_90436_850739945.dbf                     90436 NO
/u01/oradata/archivelog/1_90437_850739945.dbf                     90437 NO
/u01/oradata/archivelog/1_90438_850739945.dbf                     90438 NO
/u01/oradata/archivelog/1_90439_850739945.dbf                     90439 NO
/u01/oradata/archivelog/1_90440_850739945.dbf                     90440 NO
/u01/oradata/archivelog/1_90441_850739945.dbf                     90441 NO
/u01/oradata/archivelog/1_90442_850739945.dbf                     90442 NO
......
复制

同时,我还在OS(CentOS 6.6 x86_64) 上找到了存档日志,
[oracle@oracledg2 archivelog]$ ls -lrth |grep 90384
-rw-r----- 1 oracle oinstall   36M Aug 25 14:02 1_90384_850739945.dbf
[oracle@oracledg2 archivelog]$ ls -lrth |grep 90435
-rw-r----- 1 oracle oinstall   27M Aug 25 14:02 1_90435_850739945.dbf
复制

我的PL/SQL代码如下,在SQL * Plus上执行它并有一些错误,
 
SYS@standby> begin
  2  for sequence in 90385 .. 90435
  3  loop
  4    execute immediate 'alter database register logfile '/u01/oradata/archivelog/1_' || sequence || '_850739945.dbf'';
  5  end loop;
  6  end;
  7  /
  execute immediate 'alter database register logfile '/u01/oradata/archivelog/1_' || sequence || '_850739945.dbf'';
                                                                               *
ERROR at line 4:
ORA-06550: line 4, column 80:
PLS-00103: Encountered the symbol "_" when expecting one of the following:
* & = - + ; < / > at in is mod remainder not rem return
returning  <> or != or ~= >= <= <> and or
like like2 like4 likec between into using || bulk member
submultiset
复制

请给我一些建议,谢谢!

最好的问候
赵全文

专家解答

你需要逃避引号,例如

execute immediate 'alter database register logfile ''/u01/oradata/archivelog/1_' || sequence || '_850739945.dbf''';
                  ^                                ^                                                            ^
                 normal                           escaped                                               escaped followed by normal
复制





「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论