What is the Difference between Procedure and Function.Can we
call a Function in a DML?
Answer Posted / ankush
Function always return a value. procedure may or may be not.
IN a select statement function may be called but we should
execute the procedure.
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.
| Is This Answer Correct ? | 3 Yes | 0 No |
Post New Answer View All Answers
What will you get by the cursor attribute sql%rowcount?
What is nvarchar in sql?
what is a database transaction? : Sql dba
Why commit is not used in triggers?
Can we join more than 2 tables in sql?
What is a schema? How is it useful in sql servers?
What is %type in pl sql?
What does select * from mean in sql?
Is a view faster than a stored procedure?
What action do you have to perform before retrieving data from the next result set of a stored procedure ?
How do I partition a table in sql?
What are different types of sql commands?
What is rowtype?
Is pl sql better than sql?
how to drop an existing table in mysql? : Sql dba