If you write a function and procedure with performs same task and return a value, which will execute fast and why.

Questions by amahanit   answers by amahanit

Showing Answers 1 - 3 of 3 Answers

ravgopal

  • Oct 10th, 2007
 

Both will take same time to execute, since both are compiled and stored in database in binary form.  So there shouldn't be any difference between both.

  Was this answer useful?  Yes

hi ravgopal i got u'r reply,thanks. but there is still one query ,in procedures OUT and INOUT parameters are copied from actual parameters to formal parameters(it takes extra time),so to improve the performance NOCOPY compiler hint if given it uses refrence method,but function returns the value as the function's result, so it won't take extra time to execute. So if my funda is correct then tell me which will execute fast and is there any package to get the execution time of subprograms.

  Was this answer useful?  Yes

Function: Whenever a function executes it returns value.
ex:
create or replace function sum(x number)
as
y number;
begin
    y:=x+2;

    return y;    -- this is necessary as the function returns the value
    dbms_output.put_line(y);
end;

select sum(3) from dual;
OUTPUT:
5

Procedure: whenever a procedure is executed a message is displayed as "PL/SQL procedure is successfully created" but we really cant find whether the logic that we need to implement in the procedure is correct, as it doesnt return the value.

--customer is the name of the table
create or replace procedure cust_procedure(name varchar,id number,address varchar)
is
begin
   insert into customer(name,id,address)  values(name,id,address);
end;

OUTPUT:
PL/SQL procedure is created sucessfully;

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions