Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> bug: pl/sql object generating function executes too many times
I've written some types that contain pl/sql static functions that
generate instances of these types (what I would call constructors in an
object oriented programming language).
What I'm observing is that, although I only execute the function once,
the server runs the function multiple times. I have two problems with
this:
Below I've included a small test case which illustrates the problem. Note how many times the dbms_output.put_line call is executed. The number of times the function's body gets invoked seems to be related to the number of members in the object type. Is there some qualifier I need to add the function declaration so that it only gets called once?
CREATE OR REPLACE TYPE Penta AS OBJECT (
aa integer,
ab float,
ac float,
ad integer,
ae float,
static FUNCTION buildPenta(a integer) return Penta
);
/
show err;
CREATE OR REPLACE TYPE BODY Penta AS
static FUNCTION buildPenta(a integer)
RETURN Penta
AS
BEGIN
dbms_output.put_line('hello'); return new Penta(a,a,a,a+1,a-1);
set serveroutput on;
create table ptable( a penta);
insert into ptable values( penta.buildPenta(4));
SQL> insert into ptable values( penta.buildPenta(4));
hello
hello
hello
hello
hello
hello
1 row created.
SQL> select * from ptable;
A(AA, AB, AC, AD, AE)