I first created a Type and then created a Table and then inserted 1 row into the table which was successful but when I fire the Select query on Table I get errors:
create type My_type as Object
(
fname varchar2(10),
lname varchar2(10)
);
Now created the table
create table My_table
(
name My_type,
phone number
);
Inserted a row
insert into My_table values ( My_type('Abc','Xyz'), 122);
Fire the Select query
select * from My_table;
Error : ORA-00932: inconsistent datatypes: expected NUMBER got OODB.MY_TYPE
select name.fname, name.lname, phone from My_table;
Error : ORA-00904: “NAME”.”LNAME”: invalid identifier
select My_type.fname, My_type.lname, phone from My_table;
Error : ORA-00904: “MY_TYPE”.”LNAME”: invalid identifier
If you use a current version of SQL*Plus, this should work
It is possible that if you’re using a really old version of SQL*Plus or if you’re using some other client tool that the client tool doesn’t know how to handle object types.
Outside of classroom exercises, you don’t generally define tables that have object types in the real world. It’s much more common to use object types in PL/SQL code to simplify processing– dealing with objects that are stored as part of the data model, on the other hand, tends to be problematic.