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

Pls can anyone give me the descriptive programing script to find the number of edit boxes in a login window in flights reservation (windows application only not web). Pls anyone, very urgent

1 Answers  


How to differentiate the webedit field like user name and password? Please tell any other best answer is ther

3 Answers   Navis,


i have data in excel sheet.i imported the data in data table.while doing parameterization,how the code knows it is a valid or invalid data?

2 Answers   Fiserv,


how i can delete the excel process for the task manager using QTP

2 Answers  


what is the difference between function and subroutine ....here every one knows theoretically...here my QUESTION IS WHAT IS THE MEANING OF FUNCTION CAN RETURN A VALUE AND SUB CAN NOT RETURN A VALUE .....WHAT DOE'S IT MEAN FUNCTION CAN RETURN A VALUE HOW FUNCTION CAN AND SUB CAN'T ....GIVE A EXAMPLE FOR BOTH ....HOW IT CAN AND CAN NOT...HELP ANDY ONE....

1 Answers   HCL,






Hi everybody, Can anybody tell me that how the QTP frameworks are implemented . I wanted to know with examples . Thanks in advance

2 Answers  


I have qtp 9.5 demo ver,I am not able to record the yahoo broeser.so anyone can tell me what setting i have to do in QTP for yahoo brower recording. why its not recognise the object of yahoo browser????

0 Answers  


Anybody explain me, the concept of checkpoint declaration in the QTP mainly for the Objects, Pages, Text and Tables ?

1 Answers  


what is a file system object in QTP

7 Answers  


list me out the shortcutkeys for some functionlities in the qtp for example to record ,to run ... etc

2 Answers   CTS,


how to retrieve data from flight resevation->reports

2 Answers   Wipro,


Can we use smart identification in Keyword Driven approach? If yes , How we can use. Please Explain?

1 Answers  


Categories