Simple example of a type stored in a table

Nothing fancy today, this is just a placeholder for using object types as a column in a table.

SQL> create type mytype as object (p_name varchar2(20),p_age number);
  2  /

SQL> create table type_table(c mytype);

Table created.

SQL> insert into type_table values(mytype('steve',44));

1 row created.

SQL> commit;

Commit complete.

SQL> select * from type_table;

C(P_NAME, P_AGE)
--------------------------------------------------------------------------------
MYTYPE('steve', 44)

SQL>

You can then query the data with something like…

SQL> select t.c.p_Name from type_table t;

C.P_NAME
--------------------
steve

SQL> select t.c.p_age from type_table t;

   C.P_AGE
----------
        44

SQL>

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.