1

可以说我有:

create type address as object (
   line1 varchar2(50),
   city varchar2(50),
   member procedure insert_address(line1 varchar2, city varchar2)
)
/

create table address_table of address;

create type body address as
   member procedure insert_address(line1 varchar2, city varchar2) is
   begin
       insert into address_table values (line1, city);
       commit;
   end insert_address;
end;
/

我怎么打电话insert_address

通过执行以下操作,我得到invalid number or types of arguments

begin
   address.insert_address('123 my road','london');
end;

我可以做到这一点并且它有效,但似乎是个坏主意:

declare
  v_address address := new address(null,null);
begin
  v_address.insert_address('123 my road','london');
end;

谢谢

4

2 回答 2

2

使用static代替member您的程序:

static procedure insert_address(line1 varchar2, city varchar2)

然后你可以在对象类型而不是实例上调用它:

address.insert_address('123 my road','london');

有关详细信息,请参阅使用 PL/SQL 对象类型

于 2010-02-24T13:15:41.357 回答
0

正如您构建它(这很奇怪),过程 insert_address 只能在地址类型的对象的上下文中调用,并且必须使用参数 line1 和 city 调用,其值与您调用它的对象无关“为了”。这就是我构建表格和代码并使用它的方式:

create table address_table (line1 varchar2(50), city varchar2(50));

create package address_pkg as
   procedure insert_address(p_line1 varchar2, p_city varchar2);
end;
/

create package body address_pkg as
   procedure insert_address(p_line1 varchar2, p_city varchar2) is
   begin
      insert into address_table (line1, city) values (p_line1, p_city);
   end;
end;
/

exec address_pkg.insert_address ('123 my road', 'london');

使用您更时髦的模型,似乎 insert_address 过程应该将“地址对象本身”插入表中。就像是:

create type address as object (
   line1 varchar2(50),
   city varchar2(50),
   member procedure insert_address
)
/

create table address_table of address;

create type body address as
   member procedure insert_address is
   begin
       insert into address_table values (line1, city);
       commit;
   end insert_address;
end;
/

然后插入就像:

declare
  v_address address := new address('123 my road','london');
begin
  v_address.insert_address;
end;
于 2010-02-24T13:24:59.717 回答