As salamo alaikum wa rahmatullah
CREATE OR REPLACE TYPE PersonObj AS OBJECT (
first_name VARCHAR2(50),
last_name VARCHAR2(50),
date_of_birth DATE,
MEMBER FUNCTION getAge RETURN NUMBER
)
create or replace type body PersonObj AS
Member Function getAge Return Number AS
Begin
Return Trunc(Months_Between(Sysdate,date_of_birth)/12);
End getAge;
End;
create table people
(
id number(2), person PersonObj);
INSERT INTO people
VALUES (1, PersonObj('John','Doe',
TO_DATE('01/01/1999','DD/MM/YYYY')))
COMMIT
DECLARE
v_person PersonObj;
BEGIN
v_person := PersonObj('Jane','Doe',
TO_DATE('01/01/1999','DD/MM/YYYY'));
INSERT INTO people VALUES (2, v_person);
COMMIT;
END;
SELECT p.id,
p.person.first_name,
p.person.getAge() age
FROM people p;
CREATE OR REPLACE TYPE PersonObj AS OBJECT (
first_name VARCHAR2(50),
last_name VARCHAR2(50),
date_of_birth DATE,
MEMBER FUNCTION getAge RETURN NUMBER
)
create or replace type body PersonObj AS
Member Function getAge Return Number AS
Begin
Return Trunc(Months_Between(Sysdate,date_of_birth)/12);
End getAge;
End;
create table people
(
id number(2), person PersonObj);
INSERT INTO people
VALUES (1, PersonObj('John','Doe',
TO_DATE('01/01/1999','DD/MM/YYYY')))
COMMIT
DECLARE
v_person PersonObj;
BEGIN
v_person := PersonObj('Jane','Doe',
TO_DATE('01/01/1999','DD/MM/YYYY'));
INSERT INTO people VALUES (2, v_person);
COMMIT;
END;
SELECT p.id,
p.person.first_name,
p.person.getAge() age
FROM people p;
----------------
output
------------
--
Ma asalaam
Passion 4 Oracle
No comments:
Post a Comment