views:

97

answers:

1

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.

A: 

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.

Tony Andrews