0

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

Please help me to resolve the error in 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;
Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55

2 Answers2

1

The Problem is not related to your Type Definition, provided that the type name is exactly specified as AST [ without quotes ] or "AST" [ inside quotes but all in upper-case letters ]

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.

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

( Assume in this case that table Product exists and has a column called 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
Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55
  • If the problem is with the product table, why does the error refer to AST? – Alex Poole Jul 27 '18 at 16:57
  • @AlexPoole Yes, exactly you're right Alex, thank you. I suspected then but I missed that part because of the all-Upper Case`'AST'` in the explanation of `PLS-00201` +1 – Barbaros Özhan Jul 27 '18 at 21:08
  • Thanks all.. I have done the change and made in upper case. but still getting the error. I have created type in ARCH scema and executing the package in INV_TEMP scema. TYPE CREATION : CREATE OR REPLACE TYPE ARCH.AST AS VARRAY(255) OF varchar2(100);CREATE OR REPLACE PACKAGE ABC IS FUNCTION F_PRODUCT_NAME(P_ATTRIBUTE_UA_NAME IN PRODUCT.Attribute_Ua_Name%TYPE) RETURN ARCH.AST; END ABC; – Deepak Patil Jul 30 '18 at 11:35
1

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. 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).

Then from your INV_TEMP schema you need to:

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:

  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.

Alex Poole
  • 183,384
  • 11
  • 179
  • 318
  • I have created a package and table in same schema (ARCH) and type is created in different schema (INV_TEMP). – Deepak Patil Jul 30 '18 at 11:44
  • 1
    @DeepakPatil - OK, then the function return should be `RETURN INV_TEMP.AST`. But as that user you might also need to `grant execute on AST to ARCH`. – Alex Poole Jul 30 '18 at 11:49