Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Procedure & function difference

2621063Feb 28 2015 — edited Feb 28 2015

Hi All,

After referring to few tutorials, I came to know that the difference between the procedure & function is that procedure may or may not return a value where as function should return a value to the calling program.Given below is my procedure. It would compare the least of two numbers & would return the smallest one

create or replace procedure findmin

(

  x in number,

  y in number,

  z out number

)

is

begin

  if(x<y) then

    z:=x;

  else

    z:=y;

  end if;

end;

declare

  c number;

begin

  findmin(23,45,c);

  dbms_output.put_line(c);

end; 

Here is my function even this does the same thing.

create or replace function findmin_fun

(

  x in number,

  y in number

)

return number

is

z number;

begin

if(x<y) then

  z:=x;

else

  z:=y;

end if;

return z;

end;

declare

begin

dbms_output.put_line(findmin_fun(56,28));

end;

I would like to know under what are all the scenarios the procedure & function would be used. And also would like to know could function do the dml operations like insert, update & delete

If so, could you guys explain me with few examples of exhibiting DML opeations in functions  

This post has been answered by unknown-7404 on Feb 28 2015
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 28 2015
Added on Feb 28 2015
3 comments
1,330 views