GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Oracle  >  PL/SQL
Go To First  |  Previous Question  |  Next Question 
 PL/SQL  |  Question 194 of 241    Print  
what are purity rules for functions? why they use ? what effects if not follow these rules?

  
Total Answers and Comments: 3 Last Update: December 10, 2007     Asked by: suhasshah2007 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: joybanerjee
 
The  purity level defines  what structure the  function reads  or  modifies.
the  types  of  purity level:

1)wnds--write  no database  stage  I.e  the  function  does not modify any database  or tables.
2)rnds--reads  no database state.  i.e function does not  read  any database  tables.
3)wnps--write  no package  state  i.efunction does not modify any packaged variables.
4)rnps-read  no package  state i.e function does not  read  any  package variables.
       

Above answer was rated as good by the following members:
kperumal75, ratna82
October 13, 2007 02:36:00   #1  
amahanit Member Since: October 2007   Contribution: 13    

RE: what are purity rules for functions? why they use ...
to use a user defined function in SQL statement purity level is established using pragma restrict_refrences. puriy levels are WNDS WNPS RNDS RNPS.
 
Is this answer useful? Yes | No
December 04, 2007 09:52:59   #2  
malik.aman Member Since: December 2007   Contribution: 4    

RE: what are purity rules for functions? why they use ? what effects if not follow these rules?
To be callable from SQL statements a stored function (and any subprograms called by that function) must obey certain purity rules which are meant to control side effects:

  • When called from a SELECT statement or a parallelized INSERT UPDATE or DELETE statement the function cannot modify any database tables.

  • When called from an INSERT UPDATE or DELETE statement the function cannot query or modify any database tables modified by that statement.

  • When called from a SELECT INSERT UPDATE or DELETE statement the function cannot execute SQL transaction control statements (such as COMMIT) session control statements (such as SET ROLE) or system control statements (such as ALTER SYSTEM). Also it cannot execute DDL statements (such as CREATE) because they are followed by an automatic commit.

If any SQL statement inside the function body violates a rule you get an error at run time (when the statement is parsed).

To check for violations of the rules you can use the pragma (compiler directive) RESTRICT_REFERENCES. The pragma asserts that a function does not read or write database tables or package variables. For example the following pragma asserts that packaged function credit_ok writes no database state (WNDS) and reads no package state (RNPS):

CREATE PACKAGE loans AS FUNCTION credit_ok RETURN BOOLEAN; 
PRAGMA RESTRICT_REFERENCES (credit_ok WNDS RNPS); END loans;
 
Is this answer useful? Yes | No
December 10, 2007 02:15:35   #3  
joybanerjee Member Since: November 2007   Contribution: 19    

RE: what are purity rules for functions? why they use ? what effects if not follow these rules?
The purity level defines what structure the function reads or modifies.
the types of purity level:

1)wnds--write no database stage I.e the function does not modify any database or tables.
2)rnds--reads no database state. i.e function does not read any database tables.
3)wnps--write no package state i.efunction does not modify any packaged variables.
4)rnps-read no package state i.e function does not read any package variables.

 
Is this answer useful? Yes | NoAnswer is useful 3   Answer is not useful 0Overall Rating: +3    


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape