在 Oracle DB 的另一个模式中重新编译同义词

Recompiling a synonym in another schema of Oracle DB

我想在另一个模式中重新编译损坏的同义词,但收到有关权限的错误。

根据 Oracle 声明:

To modify a private synonym in another user's schema, you must have the CREATE ANY SYNONYM and DROP ANY SYNONYM system privileges.

好的,请看我的代码片段:

SQL*Plus: Release 11.2.0.1.0 Production on Thu Sep 24 18:47:29 2020

Copyright (c) 1982, 2010, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Release 11.2.0.4.0 - 64bit Production

SQL> select user, sys_context( 'userenv', 'current_schema' ) cur_schema from dual;

USER
------------------------------
CUR_SCHEMA
--------------------------------------------------------------------------------
STAT_ADM
STAT_ADM


SQL> SELECT s.privilege
  2    FROM dba_sys_privs s
  3   WHERE s.grantee = USER
  4     AND s.privilege LIKE '%ANY%SYNONYM%';

PRIVILEGE
----------------------------------------
DROP ANY SYNONYM
CREATE ANY SYNONYM

SQL> alter synonym ADB011_T_PRO.SA_BRAND compile;
alter synonym ADB011_T_PRO.SA_BRAND compile
*
ERROR at line 1:
ORA-01031: insufficient privileges


SQL> select dbms_metadata.get_ddl(object_type => 'SYNONYM'
  2                              ,NAME        => 'SA_BRAND'
  3                              ,SCHEMA      => 'ADB011_T_PRO') ddl_code from dual;

DDL_CODE
--------------------------------------------------------------------------------

  CREATE OR REPLACE SYNONYM "ADB011_T_PRO"."SA_BRAND" FOR "STAT_INT"."SA_BRAND"


SQL>

我真的缺少一些许可吗?或者我应该如何正确地重新编译同义词?我也有 CREATE ANY SYNONYM 权限,因此我通过发出此同义词的 DDL 语句使其再次有效来解决它,但我想使用编译选项。

这似乎被记录为 Oracle Bug 4189542 (Doc ID 4189542.8)。从您的代码来看,您似乎正在使用 11.2.0.4 版数据库。如果您更新您的 Oracle 版本,或将最新的补丁集应用到您的 11.2.0.4 数据库,那么它应该可以解决该问题。