I need to extract and display all the years for all the records in db using member function in oracle 11g.
CREATE or replace TYPE BODY student_t AS
MEMBER FUNCT
It is much simpler:
yearDOB SYS_REFCURSOR;
BEGIN
OPEN yearDOB for
SELECT EXTRACT(YEAR FROM s.dob) c_year
from student s;
return yearDOB;
END;
I'm not sure what you are trying to achieve but I think you misunderstood concept of object in oracle.
In my example i'm assuming
1) Table studens is create with this script create table student of student_t;
drop table student;
Create type spec and body.
create or replace type student_t as object(
stno char(4),
dob date,
member function getYear return number
)
;
create or replace type body student_t as
member function getYear return number is
begin
return EXTRACT(YEAR FROM self.dob);
end;
end;
Create table of studnets
create table student of student_t;
Populate tabel
declare
v_student student_t;
begin
for i in 0 .. 10 loop
insert into student values(student_t('ST'||+mod(i,3),to_date('01-01-'||to_char(2000+i),'dd-mm-yyyy')));
end loop;
commit;
end;
And the query.
select s.*,s.getYear() from student s;