I have such objects and methods:
create or replace type PolicyType as object(
policy_id number,
policy_nr varchar2(20),
price number) NOT FINAL;
/
create or replace type TravelerType as object(
first_name varchar2(30),
last_name varchar2(30),
pers_code varchar2(12));
/
create or replace type TravelersType as table of TravelerType;
/
create or replace type ref_TargetPlaceType as object (
target_code varchar2(4),
description varchar2(30));
/
create or replace type TravelPolicyType under PolicyType (
target_code REF ref_TargetPlaceType,
traveler_data TravelersType,
MEMBER FUNCTION getTraveler (p_code IN varchar2) RETURN TravelerType,
MEMBER PROCEDURE addTraveler( traveler IN TravelerType ));
/
CREATE OR REPLACE TYPE BODY TravelPolicyType AS
MEMBER FUNCTION getTraveler(p_code IN varchar2) RETURN TravelerType AS
BEGIN
for i in 1 .. self.traveler_data.count() loop
if( self.traveler_data(i).pers_code = p_code )
then
return self.traveler_data(i);
end if;
end loop;
END;
MEMBER PROCEDURE addTraveler(traveler IN TravelerType) AS
BEGIN
self.traveler_data.extend();
self.traveler_data(self.traveler_data.count) :=traveler;
END;
END;
I am tying to call methods, bet getting error for both ORA-04063: type body "SQL_LPZCXWDSKRAXJUEWPMXNUMWYH.TRAVELPOLICYTYPE" has errors ORA-06512:
declare
policy_d TravelPolicyType;
traveler TravelerType;
begin
select value(a) into policy_d from travel_policies a where a.policy_nr='TP00000000003';
traveler:=policy_d.getTraveler('050976-12568');
end;
declare
policy_d TravelPolicyType;
new_traveler TravelerType;
begin
select value(a) into policy_d from travel_policies a where a.policy_nr='TP00000000003';
new_traveler:=TravelerType('Test','Traveler', '123456-44444');
policy_d.addTraveler(new_traveler);
end;
Can not understand what I am doing wrongly. Please help with advise
CodePudding user response:
See what errors are reported in that object:
select * from user_errors;
NAME | TYPE | SEQUENCE | LINE | POSITION | TEXT | ATTRIBUTE | MESSAGE_NUMBER |
---|---|---|---|---|---|---|---|
TRAVELPOLICYTYPE | TYPE BODY | 1 | 4 | 22 | PLS-00302: component 'TRAVELERS_DATA' must be declared | ERROR | 302 |
TRAVELPOLICYTYPE | TYPE BODY | 2 | 4 | 3 | PL/SQL: Statement ignored | ERROR | 0 |
Your type has traveler_data
, but the body refers to travelers_data
. You need to make that naming consistent.