Re: Cannot call function in query

From: G Credland <G.Credland_at_shef.ac.uk>
Date: 1997/06/04
Message-ID: <339557BE.AC4_at_shef.ac.uk>#1/1


Rowan McCammon wrote:
>
> PL/SQL: I've declared a function in a package that simply
> returns a constant.
>
> When I use this function in a SQL query I get an error
> message that tells me something like "Cannot perform
> query as database may be updated. Cannot guarantee non-
> update."
>
> If I then define a copy of this function outside the
> package (i.e.. simply a stored function) and call it from
> within a query, the query works fine.
>
> Can anyone explain this to me?
>
> Any help appreciated,
> Rowan McCammon.

When the function is compiled independently, its code is visible and can be checked that it does not write to the database. When the function is placed in a package, only the declaration line is visible. You therefore need a special clause to guarantee that the function can be used without it updating the database.

In the package header use:

FUNCTION bob(xyz IN NUMBER);
PRAGMA RESTRICT REFERENCES(bob, WNDS, WNPS, RNPS);

WNDS - Does not write to database
RNDS - Does not read from the database
WNPS - Does not write to package state
RNPS - Does not read package state

The important one is WNDS I believe.

George Credland
Mailto:g.credland_at_shef.ac.uk Received on Wed Jun 04 1997 - 00:00:00 CEST

Original text of this message