What is difference between function and procedure?

Answer Posted / smruti

ALL THE BELOW ARE NOT CORRECT GUYS. WHY DON'T VERIFY ONE BY
ONE : CHECK THE COMMENTS


1. Function is mainly used in the case where it must return
a value. Where as a procedure may or may not return a value.
or may return more than one value using the OUT parameter.


CORRECT.(DIFFERENCE NUMBER # 1) MAKE A NOTE.

2. Function can be called from SQL statements where as
procedure can not be called from the sql statements

THIS IS PARTIALLY TRUE, BECAUSE A STATEMENT IS TRUE IF
EVERY TEST CASE IS TRUE. A FUNCTION CONTAINING DMLS CAN'T
BE CALLED FROM SQL STMT SO ITS SAME AS PROCEDURE.

-- > NO DIFFERENCE


3. Functions are normally used for computations where as
procedures are normally used for executing business logic.

WHO SAID FUNCTIONS ARE ONLY USED FOR CALCULATIONS. CAN'T
YOU UPDATE A TABLE OR VALIDATE SOMETHING?

--> NO DIFFERENCE

4. You can have DML (insert,update, delete) statements in a
function. But, you cannot call such a function in a SQL
query.

DIFINED ABOVE

--> NO DIFFERENCE

5. Function returns 1 value only. Procedure can return
multiple values (max 1024).

-- > DIFINED ALREADY IN POINT 1 THE ONLY DIFFERENCE

6.Stored Procedure: supports deferred name resolution.
Example while writing a stored procedure that uses table
named tabl1 and tabl2 etc..but actually not exists in
database is allowed only in during creation but runtime
throws error Function wont support deferred name resolution.

WHO SAID PROCEDURE DONT RAISE ERROR IF YOU CREATE IT
WITHOUT A DATABASE TABLE. IT GIVES WARNING AND IF U CREATE
A FUNCTION ALSO WITHOUT A TABLE IT GETS CREATED WITH
WARNING.

--> NO DIFFERENCE

SQL> CREATE OR REPLACE PROCEDURE PC1 (P1 IN NUMBER) IS
2 DUMMY NUMBER;
3 BEGIN
4 SELECT 1 INTO DUMMY FROM PROD;
5 END;
6 /

Warning: Procedure created with compilation errors.

SQL> SHOW ERROR
Errors for PROCEDURE PC1:

LINE/COL ERROR
-------- ---------------------------------------------------
--------------
4/1 PL/SQL: SQL Statement ignored
4/26 PL/SQL: ORA-00942: table or view does not exist

==========================================================

SQL> CREATE OR REPLACE FUNCTION FUNC2 (P1 IN NUMBER,
2 P2 OUT NUMBER)
3 RETURN NUMBER IS
4 L_DUMMY NUMBER;
5 BEGIN
6 PC1 (1);
7 SELECT 1 INTO L_DUMMY FROM PROD;
8 RETURN L_DUMMY;
9 END;
10 /

Warning: Function created with compilation errors.

SQL> SHO ERR
Errors for FUNCTION FUNC2:

LINE/COL ERROR
-------- ---------------------------------------------------
--------------
7/1 PL/SQL: SQL Statement ignored
7/28 PL/SQL: ORA-00942: table or view does not exist



7.Stored procedure returns always integer value by default
zero. where as function return type could be scalar or table
or table values

--> NOT ALWAYS TRUE SO NO DIFFERENCE

8. Stored procedure is precompiled execution plan where as
functions are not.


--> WRONG NO DIFFERENCE

9.A procedure may modify an object where a function can only
return a value The RETURN statement immediately completes
the execution of a subprogram and returns control to the
caller.

--> FUNCTION CAN MODIFY AN OBJECT BY DMLS
--> NO DIFFERENCE



SO FINALLY YOU WILL GET ALMOST NO DIFFERENCE EXCEPT ONE
FUNCTION RETURNS ONLY 1 VALUE WHERE AS PROCEDURE MAY OR MAY
NOT OR MORE THAN ONE, WHICH IS ALSO FALSE WHEN PROCEDURE
MADE TO RETURN ONE VALUE.

-> MAY BE YOU WILL FIND THIS USEFUL.

RUN AN EXECUTION PLAN ON PROC AND FUNC YOU WILL FIND
FUNCTION EXECUTES MUCH MUCH FASTER THAN PROC BECAUSE THE
RETURN CLAUSE IN FUNCTION IS A PRECOMPILER DIRECTIVE
LIKE "PRAGMA" WHICH SHOW THIS IS GOING TO RETURN ONE VALUE
DEFINITELY AND THAT TO OF SPECIFIC DATATYPE SO COMPILER
GETS READY FOR IT WITH THE PRE-INSTRUCTIONS.

Guys this is nothing personal but the facts i found by
experimenting. Let me know if you found anything false.

Tx

Is This Answer Correct ?    13 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

I would like to directly import XL file and work on that XL file directly in QTp script in that XL sheet need to allocate workbench,XL sheet and generate two bar graphs automatically how to do that? plz let me know any answers?

1569


Will down time for server and content maintenance/upgrades be allowed? how much?

619


Is virtual object supported in low level recording mode?

630


How to add verification steps to tests?

9134


how to use the QTP choose the data from oracle? e.g. i input the identity card NO. this will be add new record in the database ,and now i want get this record's prime key.

1330






In qtp, explain what is keyword driven automation framework?

624


Hi Friends, How many types of Data Bases available in market... What is the diff. while using Syabase and Oracle in a Project... ? and what is the main diff. of Syabase and Oracle databases... ? Thanx in advance..

1525


How to call a test from another test?

690


What is a reusable action?

581


i am new QTP... please tell me automation frameworks , types & for whiich type of applications frameworks are used & how to generate script in keyword driven framework

1614


what are the challenges you have faced while testing web based application using the automation tools ?

602


Explain the features and benefits of quick test pro(qtp)?

520


what is the advantages and disadvantages of using functions instead of re usable actions

1437


Hi we are using QTP9.0 for Seibel Application and this seibel application will give you a popup messagebox which is of web , so qtp takes 3 mins to recognize the messagebox and to click on it , we have more number of messageboxes like this . please suggest me some solution

1671


How can we retrieve the Bug Ids which are open&Reopen in status through QTP scrit?Please find the script which i tried... Dim objBugFactory, objBug Dim BugId Set TDConnection = QCUtil.TDConnection Set objBug = TDConnection.BugFactory If QCUtil.IsConnected then Reporter.ReportEvent 0, "Connected", "Connected to server: " + QCUtil.TDConnection.ServerName + chr (13) +"Project: " + QCUtil.TDConnection.ProjectName + chr (13) + "Domain: " + QCUtil.TDConnection.DomainName Reporter.ReportEvent 0, "Current time on server is","==>" & TDConnection.ServerTime Else Reporter.ReportEvent 1, "Not connected", "Not connected to Quality Center" End If If mybug.Status="Open" Then BugId=mybug.DefectId MsgBox BugId End If 'OR**********************************--------------------- -----********************************** If Bug_Fields("BG_STATUS").Value ="Open" Or "Re Open"Then BugId=Bug_Fields("BG_BUG_ID").Value MsgBox BugId End If

2584