GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Database  >  Stored Procedures
Go To First  |  Previous Question  |  Next Question 
 Stored Procedures  |  Question 9 of 12    Print  
Why the stored functions can not be called from DML Statements? Why cant we modify the database by function?

  
Total Answers and Comments: 4 Last Update: November 24, 2009     Asked by: Appu 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: krishnaindia2007
 
>>Why the stored functions can not be called from DML Statements? 
We can call a stored function from dml statement.

Here is simple example

CREATE OR REPLACE FUNCTION TEST_1 RETURN NUMBER IS

BEGIN

RETURN(10);

END;


SELECT TEST_1 FROM DUAL;

update emp

set sal = sal+ sal*test_1();


To be called from an sql statement a function should follow the following purity rules.
1) When called from a SELECT statement , the function should not modify database objects.
2) When called from INSERT , UPDATE, DELETE statements , the function can not query or modify the tables that was  modified by the statement.
3)When called from SELECT , DELETE, UPDATE, INSERT Statements , a function should not contain TCL, DDL commands.

>>Why cant we modify the database by function

The main purpose of a function is to compute a value. Generally we use procedures to make modifications in database. If you want you can do modifications using functions also. But you can't call such functions from DML statements.



 

Above answer was rated as good by the following members:
ibrarx, sandeep549
September 02, 2007 18:03:02   #1  
Vaibhav Doshi        

RE: Why the stored functions can not be called from DM...
While Creating the stored functions It check the Purity Level ( WNDS RNDS WNPS RNPS ). so functions can not modify any database by using DML.
 
Is this answer useful? Yes | No
March 10, 2008 03:42:52   #2  
sampra Member Since: February 2008   Contribution: 278    

RE: Why the stored functions can not be called from DML Statements? Why cant we modify the database by function?
give me sme simple answer
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
May 26, 2008 00:55:38   #3  
krishnaindia2007 Member Since: September 2007   Contribution: 854    

RE: Why the stored functions can not be called from DML Statements? Why cant we modify the database by function?
>>Why the stored functions can not be called from DML Statements?
We can call a stored function from dml statement.

Here is simple example

CREATE OR REPLACE FUNCTION TEST_1 RETURN NUMBER IS

BEGIN

RETURN(10);

END;


SELECT TEST_1 FROM DUAL;

update emp

set sal sal+ sal*test_1();


To be called from an sql statement a function should follow the following purity rules.
1) When called from a SELECT statement the function should not modify database objects.
2) When called from INSERT UPDATE DELETE statements the function can not query or modify the tables that was modified by the statement.
3)When called from SELECT DELETE UPDATE INSERT Statements a function should not contain TCL DDL commands.

>>Why cant we modify the database by function

The main purpose of a function is to compute a value. Generally we use procedures to make modifications in database. If you want you can do modifications using functions also. But you can't call such functions from DML statements.




 
Is this answer useful? Yes | NoAnswer is useful 2   Answer is not useful 0Overall Rating: +2    
November 24, 2009 05:04:29   #4  
ushanaina Member Since: November 2009   Contribution: 1    

RE: Why the stored functions can not be called from DML Statements? Why cant we modify the database by function?

Would like to add one more point for your answer

Calling a function from select stament is not recomended as it will degrade the performance.


 
Is this answer useful? Yes | No


 
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