简体   繁体   English

尝试访问另一个模式表时获取PLS-00201

[英]Getting PLS-00201 when trying to access another schema table

I want to clean some data on SCHEMA_ADM and SCHEMA_DAT tables, but, my procedure need to be stored on SCHEMA_DAT and will be called by SCHEMA_APP. 我想清除SCHEMA_ADM和SCHEMA_DAT表上的一些数据,但是,我的过程需要存储在SCHEMA_DAT上,并由SCHEMA_APP调用。 I did the procedure like this: 我做了这样的程序:

create or replace PACKAGE BODY "PKG_CLEANING_THE_MESS"
AS
PROCEDURE PRC_DELETE_DATA (some variables...)
AS
    TYPE fooTableType
    IS TABLE OF FOO_TABLE.ID%TYPE; --TABLE ON SCHEMA_DAT. Works fine!
    fooTable fooTableType;

    TYPE xyzTableType
    IS TABLE OF XYZ_TABLE.ID%TYPE; --TABLE ON SCHEMA_ADM. The problem is here!!!
    xyzTable xyzTableType;
    ...
END PRC_DELETE_DATA;
...
END PKG_CLEANING_THE_MESS;

When I try to compile that, give me 当我尝试编译时,给我

PLS-00201: identifier 'XYZ_TABLE' must be declared. PLS-00201:必须声明标识符“ XYZ_TABLE”。

I tried "SCHEMA_ADM"."XYZ_TABLE" instead of just "XYZ_TABLE", but didn't works too. 我尝试了“ SCHEMA_ADM”。“ XYZ_TABLE”,而不仅仅是“ XYZ_TABLE”,但是也没有用。 The SCHEMA_DAT has a SIUD role to SCHEMA_ADM and a SYNONYM to XYZ_TABLE, but doing research I found that stored procedures can't use the grant of roles. SCHEMA_DAT对SCHEMA_ADM具有SIUD角色,对XYZ_TABLE具有SYNONYM,但是进行研究后发现存储过程不能使用角色授予。 But I didn't found any way to give the grants on the PROCEDURE to compile without errors and to guarantee that SCHEMA_APP also can call the procedure. 但是我没有找到任何方法来授予PROCEDURE上的授权以进行编译而不会出错,并确保SCHEMA_APP也可以调用该过程。 Any help on that? 有什么帮助吗? Thanks! 谢谢!

EDIT: I found this similar question , asked 4 years ago, but without a conclusive answer :/ 编辑:我发现了类似的问题 ,问了4年前,但没有一个明确的答案:/

The checklist for this error should be something like: 此错误的清单应类似于:

  1. Does table XYZ_TABLE exist? 表格XYZ_TABLE是否存在? (Did you spell it right? Is it actually named in double-quotes as something like "xyz_table" or "XYZ Table" ?) (您拼写正确吗?实际上是用双引号将其命名为"xyz_table""XYZ Table"吗?)
  2. Is it in the expected schema, SCHEMA_ADM ? 是否在预期模式SCHEMA_ADM
  3. Are privileges such as SELECT granted directly to the package owner, SCHEMA_DAT ? 是否将诸如SELECT之类的特权直接授予包所有者SCHEMA_DAT
  4. Is there a private or public synonym with the expected name? 是否存在预期名称的私有或公共同义词? (eg there might be a synonym X for table Y , but the code refers to Y .) (例如,表Y可能有同义词X ,但代码引用了Y
  5. Or, is the code prefixing it with the schema name eg SCHEMA_DAT.XYZ_TABLE ? 或者,代码是否以模式名称作为前缀(例如SCHEMA_DAT.XYZ_TABLE
  6. Is there a package or type with the same name as the schema ( SCHEMA_DAT )? 是否有与架构同名的软件包或类型( SCHEMA_DAT )? This could create a naming conflict where the compiler finds the package instead of the schema, and then looks in that for something called XYZ_TABLE . 这可能会导致命名冲突,编译器会在其中找到包而不是架构,然后在其中查找XYZ_TABLE

Your requirements may vary, but it's usually better to create a synonym than to hardcode the schema name (less to type, more flexibility if things change), and private synonyms are preferable to public synonyms (security, as they don't broadcast your schema structure, and more flexible in case you want to direct different users to different objects, or add another schema later with different requirements). 您的要求可能会有所不同,但是创建同义词通常比对模式名称进行硬编码(键入少,如果情况发生变化,灵活性更大)更好,并且私有同义词比公共同义词更可取(安全性,因为它们不会广播您的模式)结构,如果您想将不同的用户定向到不同的对象,或者以后添加具有不同要求的另一个架构,则更加灵活。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM