[英]Error: PLS-00201: identifier 'AST' must be declared in Package
I am getting error while running below code. 在以下代码下运行时出现错误。 I have already created a type but still getting an Error:
我已经创建了一个类型,但是仍然出现错误:
PLS-00201: identifier 'AST' must be declared
PLS-00201:必须声明标识符“ AST”
Please help me to resolve the error in ORACLE 12C . 请帮助我解决ORACLE 12C中的错误。
TYPE CREATION : 类型创建:
CREATE OR REPLACE TYPE "AST" AS VARRAY(255) OF varchar2(100);
PACKAGE CREATION : 包装方式:
CREATE OR REPLACE PACKAGE ABC IS
FUNCTION F_PRODUCT_NAME(P_ATTRIBUTE_UA_NAME IN PRODUCT.Attribute_Ua_Name%TYPE)
RETURN AST;
END ABC;
The Problem is not related to your
Type Definition
, provided that the type name is exactly specified asAST
[ without quotes ] or"AST"
[ inside quotes but all in upper-case letters ]该问题与您的
Type Definition
无关,只要类型名称完全指定为AST
[不带引号]或"AST"
[引号内,但全部使用大写字母]
If you have a table or view called Product
, and that has a column called Attribute_Ua_Name
in your current schema, there will no error raise. 如果您有一个名为
Product
的表或视图 ,并且在当前架构中有一个名为Attribute_Ua_Name
的列,则不会发生错误。
BUT It seems that the problem is due to the definition of the Type AST
inside quotes but not in all upper-case such as "AsT"
or "aST"
etc. Here's the testing case for this error 但是似乎问题是由于引号中定义了
AST
类型,而不是全部使用大写形式,例如"AsT"
或"aST"
等。这是此错误的测试案例
( Assume in this case that table Product
exists and has a column called Attribute_Ua_Name
): (在这种情况下,假设表
Product
存在并且具有名为Attribute_Ua_Name
的列):
SQL> CREATE OR REPLACE TYPE "AsT" AS VARRAY(255) OF varchar2(100);
2 /
Type created
SQL> CREATE OR REPLACE PACKAGE ABC IS
2 FUNCTION F_PRODUCT_NAME(P_ATTRIBUTE_UA_NAME IN PRODUCT.Attribute_Ua_Name%TYPE) RETURN AST;
3 END ABC;
4 /
Warning: Package created with compilation errors
SQL> show err;
Errors for PACKAGE MYSCHEMA.ABC:
LINE/COL ERROR
-------- --------------------------------------------
2/89 PLS-00201: identifier 'AST' must be declared
2/3 PL/SQL: Declaration ignored
SQL> CREATE OR REPLACE TYPE "AST" AS VARRAY(255) OF varchar2(100);
2 /
Type created
SQL> CREATE OR REPLACE PACKAGE ABC IS
2 FUNCTION F_PRODUCT_NAME(P_ATTRIBUTE_UA_NAME IN PRODUCT.Attribute_Ua_Name%TYPE) RETURN AST;
3 END ABC;
4 /
Package created
What you have works fine, assuming you actually did create the type in the same schema as the table and package; 假设您确实在与表和包相同的模式中创建类型,那么您的工作就很好了。
CREATE OR REPLACE TYPE "AST" AS VARRAY(255) OF varchar2(100)
/
Type AST compiled
create table PRODUCT(Attribute_Ua_Name varchar2(30))
/
Table PRODUCT created.
CREATE OR REPLACE PACKAGE ABC IS
FUNCTION F_PRODUCT_NAME(P_ATTRIBUTE_UA_NAME IN PRODUCT.Attribute_Ua_Name%TYPE)
RETURN AST;
END ABC;
/
Package ABC compiled
show errors
No errors.
If you get "PLS-00201: identifier 'AST' must be declared" then you either didn't actually run that statement, or you ran it in a different schema. 如果收到“ PLS-00201:必须声明标识符'AST'”,则说明您实际上没有运行该语句,或者在其他架构中运行了该语句。 If it is in a different schema then you can just prefix it with the owning schema name
如果它在不同的架构中,则可以在其前面加上拥有的架构名称
FUNCTION F_PRODUCT_NAME(P_ATTRIBUTE_UA_NAME IN PRODUCT.Attribute_Ua_Name%TYPE)
RETURN owning_schema.AST;
I have created a package and table in same schema (ARCH) and type is created in different schema (INV_TEMP).
我已经在相同的架构(ARCH)中创建了一个包和表,并且在另一个架构(INV_TEMP)中创建了类型。
Then from your INV_TEMP
schema you need to: 然后,从
INV_TEMP
模式中,您需要:
grant execute on AST to ARCH;
and the function definition needs to refer to the type owner in the package specification in the ARCH
schema: 并且函数定义需要在
ARCH
模式的包规范中引用类型所有者:
FUNCTION F_PRODUCT_NAME(P_ATTRIBUTE_UA_NAME IN PRODUCT.Attribute_Ua_Name%TYPE)
RETURN INV_TEMP.AST;
When you write the package body the function will also have to refer to the INV_TEMP
owner, both in the definition (to match the specification) and when declaring an INV_TEMP.AST
object variable or creating an object as part of a query. 当您编写包主体时,该函数还必须在定义中(以符合规范)以及在声明
INV_TEMP.AST
对象变量或在查询中创建对象时都引用INV_TEMP
所有者。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.