This script demonstrates attribute chaining. : Attribute « Object Oriented Database « Oracle PL / SQL






This script demonstrates attribute chaining.

   

SQL>
SQL> CREATE OR REPLACE TYPE addressType AS OBJECT (
  2     address1   VARCHAR2 (30 CHAR),
  3     address2   VARCHAR2 (30 CHAR),
  4     city       VARCHAR2 (30 CHAR),
  5     state      CHAR (2 CHAR)
  6  )
  7  INSTANTIABLE FINAL;
  8  /

Type created.

SQL>
SQL> CREATE OR REPLACE TYPE personType AS OBJECT (
  2     fname   VARCHAR2 (20),
  3     lname    VARCHAR2 (20)
  4  )
  5  INSTANTIABLE FINAL;
  6  /


SQL>
SQL> CREATE OR REPLACE TYPE contactType AS OBJECT (
  2     NAME      personType,
  3     address   addressType,
  4     phone     NUMBER (10)
  5  )
  6  INSTANTIABLE FINAL;
  7  /

Type created.

SQL>
SQL> CREATE OR REPLACE TYPE publisher_obj AS OBJECT (
  2     pub_name       VARCHAR2 (30),
  3     contact_info   contactType,
  4     MEMBER PROCEDURE show_contact
  5  )
  6  INSTANTIABLE FINAL;
  7  /

SP2-0816: Type created with compilation warnings

SQL>
SQL> CREATE OR REPLACE TYPE BODY publisher_obj
  2  AS
  3     MEMBER PROCEDURE show_contact
  4     IS
  5     BEGIN
  6        DBMS_OUTPUT.put_line (SELF.pub_name);
  7        DBMS_OUTPUT.put_line (SELF.contact_info.NAME.fname|| ' '|| SELF.contact_info.NAME.lname);
  8        DBMS_OUTPUT.put_line (SELF.contact_info.address.address1);
  9        DBMS_OUTPUT.put_line (SELF.contact_info.address.city);
 10        DBMS_OUTPUT.put_line (SELF.contact_info.address.state);
 11        DBMS_OUTPUT.put_line (SELF.contact_info.phone);
 12        RETURN;
 13     END show_contact;
 14  END;
 15  /

SP2-0818: Type Body created with compilation warnings

SQL>
SQL>  SET SERVEROUTPUT ON SIZE 1000000
SQL>  DECLARE
  2      v_person      personType    := personType ('R', 'A');
  3      v_address     addressType   := addressType ('1 Way', NULL, 'Springs', 'CO');
  4      v_contact     contactType := contactType (v_person, v_address, 5);
  5      v_publisher   publisher_obj := publisher_obj ('Press', v_contact);
  6   BEGIN
  7     v_publisher.show_contact;
  8   END;
  9   /
Press
R A
1 Way
Springs
CO
5

PL/SQL procedure successfully completed.

SQL>

   
    
    
  








Related examples in the same category

1.Reference type attribute through column name