Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Can I call another function inside the package?

Re: Can I call another function inside the package?

From: Johnson Chao <zhao_at_ctc-g.co.jp>
Date: Fri, 25 Jun 1999 04:33:42 GMT
Message-ID: <7kv0r6$q0m$1@nnrp1.deja.com>


Hi,:
  Thanks very much for your useful help.   Now I can do it.

 But another question comes. If Fuction AAA wil do a dabase operation, how can it be done? I have tried to add a insert statement inside AAA, but the compiling does not pass. While I remove the pragma statement away, though it can pass the compile, when executing, I was again told " Function AAA does not guarantee not to update database". How can I do that.

Thanks

In article <3770d372.0_at_145.227.194.253>,   "Mark G" <mgumbs_at_nospam.hotmail.com> wrote:
> 1. Your exception when others was not letting the real error message
filter
> up back to you so you never saw the real error problem which was.....
>
> ORA-06571: Function AAA does not guarantee not to update
database
>
> The reason why it worked when aaa was a stand-alone function is that
the
> compiler can determine the 'purity' level of stand alone functions
but not
> when it is part of a package.
>
> 2. You do not need returns in procedures.
>
> 3. Because of the nature of your for loop, you do not need to
explicitly
> declare rec1 as a rowtype of the zt table, the loop handles that for
you.
>
> 3. Because you are using a function in a sql statement, you have to
declare
> a pragma
> in the package body header for the. Look up pragma restrict
references (and
> purity) in any good book.
>
> This code should work...
>
> CREATE OR REPLACE PACKAGE try AS
> FUNCTION aaa (x IN NUMBER) RETURN number;
> pragma restrict_references(aaa, WNDS);
>
> PROCEDURE rrr (Mm number) ;
> END try;
> /
>
> CREATE OR REPLACE PACKAGE BODY try AS
> FUNCTION aaa (x IN NUMBER) RETURN number IS
> BEGIN
> return (x+10);
> END aaa;
>
> PROCEDURE rrr(mm IN number) IS
> CURSOR ccur1 IS SELECT * FROM zt where c2=mm;
>
> BEGIN
> FOR rec1 IN ccur1 LOOP
> insert into zt values(aaa(rec1.c1),rec1.c2);
> END LOOP;
>
> commit;
> END rrr;
>
> END try;
>
> -------------------------------------
> Mark
>
> <snip>
>
>

--
Johnson Chao
ctc Japan

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't. Received on Thu Jun 24 1999 - 23:33:42 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US