Use a table alias and the name of the object : Object Table « Object Oriented Database « Oracle PL / SQL






Use a table alias and the name of the object

  

SQL> CREATE OR REPLACE TYPE aobj AS object (
  2                    state CHAR(2),
  3                    amt NUMBER(5),
  4
  5                    MEMBER FUNCTION mult (times in number) RETURN number,
  6                    PRAGMA RESTRICT_REFERENCES(mult, WNDS));
  7  /

Type created.

SQL>
SQL> CREATE OR REPLACE TYPE BODY aobj AS
  2    MEMBER FUNCTION mult (times in number) RETURN number
  3    IS
  4    BEGIN
  5      RETURN times * self.amt; /* SEE BELOW */
  6    END;
  7  END;
  8  /

Type body created.

SQL> CREATE TABLE aobjtable (arow aobj);

Table created.

SQL> /
CREATE TABLE aobjtable (arow aobj)

SQL>
SQL>
SQL> INSERT INTO aobjtable VALUES (aobj('FL',25));

1 row created.

SQL> INSERT INTO aobjtable VALUES (aobj('AL',35));

1 row created.

SQL> INSERT INTO aobjtable VALUES (aobj('OH',15));

1 row created.

SQL>
SQL> -- Use a table alias and the name of the object
SQL>
SQL> SELECT x.arow.state, x.arow.amt
  2  FROM aobjtable x;

AR   AROW.AMT
-- ----------
FL         25
AL         35
OH         15

SQL>
SQL> DESC aobjtable;
 Name                                                                                                  Null?    Type
 ----------------------------------------------------------------------------------------------------- -------- --------------------------------------------------------------------
 AROW                                                                                                   AOBJ

SQL>
SQL> drop table aobjtable;

Table dropped.

SQL>
SQL>

           
         
    
  








Related examples in the same category

1.Crate table with object column
2.Create table with user defined type as column
3.Create a table with user define varray as column type
4.Create a table with nested user defined type as column
5.Object table: a table of type
6.Use user-defined varray type as column type
7.Nested table
8.Create a table based on user-defined object only
9.Implementation of many to many using object references
10.Implementation of multiple inheritance relationship
11.Implementation of one to many using object references
12.Create table based on single data type
13.Create table with nested types
14.Create type and use it as table column
15.One to one using object references
16.Use user-defined type to combine query logic
17.Create a new type and add it to a table
18.Multilevel aggregation relationships using nested tables