Postgres Plus Advanced Server Oracle Compatibility Developer's Guide : 8.3 Creating Object Instances

Previous PageTable Of ContentsNext Page

Postgres Plus Advanced Server Oracle Compatibility Developer's Guide

 

8.3 Creating Object Instances

Creating instances of an object type requires the following steps.

    ● Declare an object variable of the object type

    ● Initialize the declared object variable with initial values

The syntax for declaring an object variable is as follows.

object objtype

object is an identifier assigned to the object variable. objtype is the identifier of a previously defined object type.

The next step is to initialize the object variable with values. The initialization process is done with a default constructor method. The following is the syntax of the constructor method.

objtype ({ expr1 | NULL } [, { expr2 | NULL } ] [, ...])

objtype is the identifier of the object type’s constructor method, which has the same name as the object type. expr1, expr2, … are expressions that are type-compatible with the first attribute of the object type, the second attribute of the object type, etc. If NULL is specified, the corresponding object attribute is set to null. If an attribute is of an object type, then the corresponding expression can be null, an object initialization expression, or any expression that returns that object type.

Note: In Advanced Server, the following alternate syntax can be used in place of the constructor method.

[ ROW ] ({ expr1 | NULL } [, { expr2 | NULL } ] [, ...])

ROW is an optional keyword if two or more terms are specified within the parenthesis-enclosed, comma-delimited list. If only one term is specified, then specification of the ROW keyword is mandatory.

The following anonymous block declares a variable of type emp_obj_typ named v_emp, and initializes it.

DECLARE
    v_emp           EMP_OBJ_TYP;
BEGIN
    v_emp := emp_obj_typ (9001,'JONES',
        addr_obj_typ('123 MAIN STREET','EDISON','NJ',08817));
END;

Previous PageTable Of ContentsNext Page