从子类型初始化对象

时间:2016-06-13 18:28:35

标签: object plsql initializing

我需要从子类型B创建和初始化一个对象,在PL / SQL中使用超类型A:

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;
}

现在,当我运行以下代码时:

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

我得到以下错误:

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

我真的很感谢你对此的帮助。非常感谢。

1 个答案:

答案 0 :(得分:0)

尝试这个代码: -

 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;

或者

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;