hajduk
hajduk

Reputation: 121

Accessing table from an object

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!

Upvotes: 0

Views: 50

Answers (1)

MT0
MT0

Reputation: 167912

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

Upvotes: 2

Related Questions