0

I need to create and initialize an object from a subtype B, with supertype A in PL/SQL:

create or replace 
TYPE "A" as object{
school_category  varchar(10);
}

create or replace 
TYPE "B" UNDER A {
school_name varchar(10);
school_ranking INTEGER;
}

Now, I when I run the below code:

Declare 
   i_B B;
BEGIN
  i_B := B('name_sample', 12, A('elementary'));
END;

I get below error:

PLS-00306: wrong number or types of arguments in call to 'B'

I really appreciate your help on this. Thanks a lot.

Shahb
  • 47
  • 1
  • 6

1 Answers1

0

TRY THIS CODE:-

 Create Or Replace Type Atest As Object
    (
    School_Category  Varchar2(10)
    );

    create or replace Type Btest Under Atest (
    school_name varchar2(10),
    School_Ranking number
         );

DECLARE
  var2 Btest;
BEGIN
  var2 := Btest('Good','MySchool',2);

    Dbms_Output.Put_Line(var2. School_Category);
    Dbms_Output.Put_Line(var2. school_name);
    Dbms_Output.Put_Line(var2. School_Ranking);
End;

Or

Create Or Replace Type Atest As Object
(
School_Category  Varchar2(10)
);

create or replace Type Btest as Object  (
school_name varchar2(10),
School_Ranking number,
School_Categ  Atest
);

Declare
iobj Btest;
Begin
iobj:=Btest(school_name=>'MYSCHOOL',School_Ranking=>2,School_Categ=>Atest(School_Category=>'GOOD'));

Dbms_Output.Put_Line(Iobj.School_Name);
Dbms_Output.Put_Line(Iobj.School_Ranking);

end;
Nancy Guruswamy
  • 267
  • 1
  • 3
  • 14
  • Great.. Thank you so much Nancy for your help and answering the question.. could you please describe the "=>" symbol as well?! As far as I can see it assign a value to the attributes. But I have seen some places they use it for passing the value to an argument of a procedure or function. (I'd appreciate it If you have any document or resource explaining it) – Shahb Jun 14 '16 at 21:45