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


Please Help Members By Posting Answers For Below Questions

Do prepared statements prevent sql injection?

691


What are the sql aggregate functions?

815


Is sql similar to python?

717


How do I truncate a sql log file?

741


Mention what plvcmt and plvrb does in pl/sql?

837






What are the operators used in select statements?

773


What is t sql used for?

733


Can we use join in subquery?

779


how to create a new view in mysql? : Sql dba

685


what are the differences among rownum, rank and dense_rank? : Sql dba

742


How do you respond to dementia behavior?

722


What do you mean by “trigger” in sql?

799


what are date and time functions in mysql? : Sql dba

718


How to create your own reports in sql developer?

729


What is vector point function?

770