Purity Level within Functions
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 2 of 2

Thread: Purity Level within Functions

  1. #1
    Join Date
    Dec 2001
    Posts
    7
    Hi,

    Has anybody encountered this ?

    I have created a function , which is used in the where clause of the select query. The function is within a package with a WNDS purity level.

    There are 3 select statements within the function and it returns a value based on the queries. Since I had to use this function in the where clause , I required a purity level of WNPS as well.

    Upon adding this purity level of WNPS, I was having a compilation error that the function is not pure enough to apply WNPS. Upon trying various things, when I commented the exception section of the Function , it compiled correctly and is working.

    Can we not have an exception section, if we require a WNPS purity level ?

    Thanks
    HN

  2. #2
    Join Date
    Dec 2001
    Location
    UK
    Posts
    1,684
    This crappy packaged function reads from the database and returns a value. It also contains an exception section and it works fine on 7.3, 8i & 9i. I think your problem must be elsewhere:

    CREATE OR REPLACE PACKAGE test IS

    FUNCTION Add_Values (v_number1 IN NUMBER,
    v_number2 IN NUMBER)
    RETURN NUMBER;

    PRAGMA RESTRICT_REFERENCES (Add_Values, WNDS, WNPS, RNPS);

    END test;
    /

    CREATE OR REPLACE PACKAGE BODY test IS

    FUNCTION Add_Values (v_number1 IN NUMBER,
    v_number2 IN NUMBER)
    RETURN NUMBER IS
    v_date DATE;
    BEGIN
    SELECT sysdate
    INTO v_date
    FROM dual;

    RETURN v_number1 + v_number2;

    EXCEPTION
    WHEN OTHERS THEN
    RETURN -1;
    END;

    END test;
    /

    SELECT Sysdate FROM dual WHERE 3 = test.Add_Values(1,2);

    Note:

    The whole purity level assignment has been ditched in later versions of 8i so I wouldn't worry about it too much. Oracle decided that the fact Java stored procedures didn't need purity level assignments meant it was stupid to keep them for PL/SQL.
    Tim...
    OCP DBA 7.3, 8, 8i, 9i, 10g, 11g
    OCA PL/SQL Developer
    Oracle ACE Director
    My website: www.oracle-base.com
    My blog: www.oracle-base.com/blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width