What is difference between function and procedure?

Answers were Sorted based on User's Feedback



What is difference between function and procedure?..

Answer / pranjal

Bot functions and procedures can return values. Apart from
this following are the differences

1) Functions are used for computations where as procedures
can be used for performing business logic

2) Functions MUST return a value, procedures need not be.

3) You can have DML(insert,update, delete) statements in a
function. But, you cannot call such a function in a SQL query..
eg: suppose, if u have a function that is updating a table..
you can't call that function in any sql query.
- select myFunction(field) from sometable; will throw error.

4) Function parameters are always IN, no OUT is possible

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

6) Stored Procedure :supports deffered name resoultion
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 deffered name resolution.
Stored procedure returns always integer value by default
zero. where as function return type could be
scalar or table or table values(SQL Server).
Stored procedure is pre compiled exuction plan where as
functions are not.

7) A procedure may modifiy an object where a function can
only return a value.

Is This Answer Correct ?    205 Yes 17 No

What is difference between function and procedure?..

Answer / ravi kumar battula

1.Function returns a value, but a procedure may return or
may not return a value.
2.Function can take only input aurguments, but procedure may
take both input and out put parameters.

Is This Answer Correct ?    213 Yes 52 No

What is difference between function and procedure?..

Answer / prakash

function can return a value
procedure cannot return a value,

Is This Answer Correct ?    246 Yes 160 No

What is difference between function and procedure?..

Answer / s

function can be called inside the select statement but not
the procedure

Is This Answer Correct ?    84 Yes 28 No

What is difference between function and procedure?..

Answer / anurag arun edlabadkar

Question: Difference Between Procedure &
Function?
1). Both functions and procedures can return values.

2). Both can return multiple values, like in the case of
procedure it can return multiple values using OUT and INOUT
type parameter, while in case of function used in Report 6i,
using "PLACEHOLDER COLUMN" you can return multiple values.

3). "Complete Reference" Book say that function can use
parameters as IN, OUT, and INOUT as same as in Procedure.

/*

create function syntax

The syntax for the create function command is more
complicated than the syntax for the create procedure
command. At a high level, the syntax is

create [or replace] function [schema.] function
[(argument [in | out | inout ] [nocopy] datatype
[, argument [in | out | inout ] [nocopy]
datatype]...
)]
return datatype

*/

4). Function returns value using "Return" Key Word, where
same key word can be used in Procedure to Terminate the
program, with immidiate effect.

5). Functions are used for computations where as procedures
can be used for performing business logic.

6). Functions MUST Return a value, procedures need not be.

7). You can have DML(insert,update, delete) statements in a
function.

8). You can call a function in a Select Query where as
not Procedure.

9). Function returns 1 value only where as Procedure can
return
multiple values(max. 1024)

10). A procedure may modifiy an object where a function can
only return a value.

Is This Answer Correct ?    20 Yes 7 No

What is difference between function and procedure?..

Answer / 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

What is difference between function and procedure?..

Answer / gunesh

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.
2.Function can be called from sql statements where as
procedure cannot be called from the sql statements.
3.Functions are normally used for computations where as
procedures are normally used for executing business logic.
4.You can have DML (insert, update, delete) statements in a
function. But, you cannot call such a function in a SQL
Query.
5.A Function returns 1 value only. Procedure can return
multiple values (max 1024).
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 won’t support deferred name
resolution.
7.Stored procedure returns always integer value by default
zero. whereas function return type could be scalar or table
or table values
8.Stored procedure is precompiled execution plan where as
functions are not.
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.

Is This Answer Correct ?    13 Yes 6 No

What is difference between function and procedure?..

Answer / nafaji

1. Function can return only one value but procedure can return more than one, or may not return any value.

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

3. We can use functions in select statement but we can not use procedure in select statement.

Is This Answer Correct ?    10 Yes 4 No

What is difference between function and procedure?..

Answer / rias

Function and procedure hv got their own use.

The following are the difference between function and
procedure..

1. Function can used with select/where clause , while
procedure can't
2.we can call a function from a procedure ,but it is not
possible to call a procedure from a function

Is This Answer Correct ?    10 Yes 5 No

What is difference between function and procedure?..

Answer / rajesh trivedi

Function must returs a value, but procedure can return more
and not any value..

Fuction are used for check conditions, but procedures can
be use check condition as well as for the bussiness logic.

Is This Answer Correct ?    25 Yes 21 No

Post New Answer

More QTP Interview Questions

How to Test the mainframe application?(tell me few basic things)

3 Answers  


Which company is better amdocs or techm ???

2 Answers  


Through array we can execute the testcase how ? give me example

0 Answers   TCS,


How can i test an application like Google Earth.In my application data will be fetched from a oracle database based upon which graphs are generated..so these all are dynamic..how can i use qtp here..alongwith that how can i test the map generated by a satellite just like google earth..

0 Answers  


How we can add actions in the test using QTP?

5 Answers  






how to add a runtime parameter to a data sheet?

6 Answers  


How do you do batch testing in wr and is it possible to do in qtp, if so explain?

0 Answers  


What are different versions in Win Runner ,QTP ,Load Runner and Test Director till now and atleast please let me know new features for each version. Ex QTP8.2,QTP 8.5.QTP9.2 supports Mozilla 2.0

1 Answers   DELL,


What is method name to compare two XML files.

0 Answers  


str="QTP AUTOMATION TESTING" here how many T are there in the str finally i want to display the T

10 Answers   HCL,


How to add a standard checkpoint in your test ?

1 Answers  


I have many listboxes in my application. I have to check whether the contents inside the listboxes are in sorted order or not..can anyone please send the code as early as possible

0 Answers  


Categories