Oracle 11g SELF成员过程无效

时间:2010-02-22 16:38:57

标签: plsql oracle11g

我有以下内容:

create type customer as object (
id number, name varchar2(10), points number,
member procedure add_points(num_points number)
) not final;
/

create type body customer as
member procedure add_points(num_points number) is 
begin
   points := points + num_points;
   commit;
end add_points;
end;
/

create table customer_table of customer;
/

insert into customer_table values (customer(123,'joe',10));
/

然后我这样做是一个匿名的阻止:

declare
cust customer;
begin
select treat(value(c) as customer) into cust from customer_table c where id=123;
c.add_points(100);
end;

但没有任何反应 - 积分值保持在10。

我错过了什么?如果我将我的成员程序设为update...set...commit并传递积分和给定的ID,则可以正常工作。

感谢。

1 个答案:

答案 0 :(得分:1)

您发布的PL / SQL无效。我想你想发布这个:

declare
  cust customer;
begin
  select treat(value(c) as customer) into cust from customer_table c where id=123;
  cust.add_points(100);
end;

即。第5行“cust”而非“c”?

如果是这样,那么你所做的就是更新变量cust 中的点的值,而不是表中的值。你可以这样看:

declare
  cust customer;
begin
  select treat(value(c) as customer) into cust from customer_table c where id=123;
  cust.add_points(100);
  dbms_output.put_line(cust.points);
end;

输出:

110

更新表中的数据确实需要UPDATE语句。