Oracle 11g SELF 成员过程不工作

发布于 2024-08-22 21:55:19 字数 748 浏览 11 评论 0原文

我有以下内容:

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

谢谢。

I have the following:

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));
/

i then do this is an anonymous block:

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

but nothing happens - the points value remains at 10.

What have i missed? If i make my member procedure an update...set...commit and pass in the points and a given id, it works.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我做我的改变 2024-08-29 21:55:19

您发布的 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 语句。

The PL/SQL you posted is invalid. I guess you meant to post this:

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

i.e. "cust" not "c" on line 5?

If so, all you have done there is updated the value of points in the variable cust, not in the table. You can see that like this:

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;

Output:

110

To update the data in the table does indeed require an UPDATE statement.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文