Skip to content

Instantly share code, notes, and snippets.

@shrawanx
Created June 15, 2018 02:44
Show Gist options
  • Save shrawanx/6dea7e37c7eeabbef2f52df7a31c9e5c to your computer and use it in GitHub Desktop.
Save shrawanx/6dea7e37c7eeabbef2f52df7a31c9e5c to your computer and use it in GitHub Desktop.
UDT inheritance ,objects . Oracle
create or replace Type Personobj as object(
fisrt_name varchar(20),
last_name varchar(20),
date_of_birth Date,
member function getAge return number
);
create or replace type body Personobj as
member function getAge return number is
begin
return trunc(Months_between(sysdate,date_of_birth)/12);
end getAge;
end;
create table people(
id number(5) not null,
person Personobj
);
desc Personobj;
insert into people
values(1,Personobj('Ram','Singh',to_date('01-09-1982','DD-MM-YYYY')));
commit;
select * from people;
-- Accessing the object
select p.id,p.Person.fisrt_name as name,
p.Person.last_name as last_name ,p.Person.date_of_birth as dob,
p.Person.getAge() age
from people p;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment