【问题标题】:Oracle 11g SELF member procedure not workingOracle 11g SELF 成员程序不工作
【发布时间】:2011-01-19 17:22:04
【问题描述】:

我有以下几点:

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,它就可以工作。

谢谢。

【问题讨论】:

  • 通过处理您之前的一个问题,我知道您正在参加某种培训课程。不幸的是,他们似乎确实在训练您了解 Oracle 的一些相当神秘和毫无意义的特性!

标签: plsql oracle11g


【解决方案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语句。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-20
    • 2011-01-20
    • 2011-01-18
    • 2021-01-10
    • 2018-04-12
    • 2015-06-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多