Home > Mobile >  Accessing table from an object
Accessing table from an object

Time:06-08

Is it possible to access an existing table from an object? Here the simplified snippet:

CREATE OR REPLACE TYPE MYOBJ AS OBJECT(
MEMBER PROCEDURE MYEXPORT( ERRORS.ERRORS_ID%TYPE));

ERRORS is a table. When I write it like above I'm getting error:

PLS-00201 - identifier must be declared.

Any clue? Thanks!

CodePudding user response:

You have three issues:

  1. The syntax is

    MEMBER PROCEDURE procedure_name (argument_name data_type)
    

    You have specified the data type but not an argument name which is why you get the error message PLS-00201 - identifier must be declared. as you need to specify an identifier for the argument.

  2. table_name.column_name%TYPE declarations can be used in the PL/SQL scope but not in the SQL scope. Your object declaration is in the SQL scope so you need to fully define the data type rather than referring to a column.

  3. An object must have at least one attribute.

You want:

CREATE OR REPLACE TYPE MYOBJ AS OBJECT(
  attr1 NUMBER,
  MEMBER PROCEDURE MYEXPORT( v_errors_id NUMBER )
);
  • Related