简体   繁体   English

如何在Oracle PL / SQL类型中定义无参数构造函数?

[英]How can I define a parameterless constructor in an Oracle PL/SQL type?

How can I define a parameterless constructor in an Oracle PL/SQL type? 如何在Oracle PL / SQL类型中定义无参数构造函数? I've tried this: 我已经试过了:

create or replace type FooBar as object
(
    constructor function FooBar() return self as result
);

...

foo_bar := FooBar();

But the empty parameter list in the type declaration raises PLS-00103. 但是类型声明中的空参数列表将引发PLS-00103。

you don't need brackets after the name of the parameterless function and you need a definition for the body ot the constructor: 您无需在无参数函数的名称后面加上方括号,并且需要为构造函数的主体定义:

create or replace type FooBar as object
(
    bar NUMBER(1,0)
    ,constructor function FooBar return self as result
);
/


create or replace type body FooBar is

    constructor function FooBar return self as result
    IS
    BEGIN
    RETURN;
    END;
end;
/


    declare 
     foo foobar;
    begin
      foo := foobar();
    end;
   /

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM