i have a type created as follows:
create type age_t as object(
dob DATE,
member function age_f return number);
/
to define the body i wrote the following code:
create or replace type body age_t as(
member function age_f return number is
v_dob date;
age number(3);
v_dob := to_date(dob);
begin
age := trunc(months_between(sysdate,v_dob))/12;
return age;
end;
end;
);
/
Oracle gives me compiled with error message. Please tell me where the problem is. I am using oracle 11g sql client.
In the create body type definition, remove the brackets "()" that are after "CREATE OR REPLACE BODY age_t AS" statement and before "/". Also, take the v_dob := to_date(dob) statement into begin and end section, or initialize v_dob during creation. That is v_dob date := to_date(dob);
Correct code without compilation errors;
`create or replace type body age_t as
member function age_f return number is
v_dob date := to_date(dob);
age number(3);
begin
age := trunc(months_between(sysdate,v_dob))/12;
return age;
end;
end;
/`
You may find more here www.exploredatabase.com