Post

SQLSQL

J
Justus Blake

Posted on 23rd April 2024|54 views

0
votes

Function Vs Stored Procedure In SQL

I have recently started working on SQL, the function and Stored Procedure are seemed to be same. Can anyone tell whats the differences between Function and Stored Procedure?

 

Answers
P
Megha Sharma

Posted on 23rd April 2024

Hey Justus,

The Function and Stored Procedure are the database objects that contains a set of SQL statements to complete a task. 

 

A function is executed and compiled every time whenever it is called. It has to return values and cannot modify the data received as a parameter.

Stored Procedures are the pre-compiled objects that are compiled for the first time and its format is saved that executes whenever it is called. 

 

key differences between Function and Stored Procedure are as follows:

 

Function

Stored Procedure

The function can be used in a Select statement

Stored Procedure cannot be used in the Select statement.

The function allows the only Select statement

The procedure allows Select as well as DML statement.

The function must return a value

Stored Procedure is optional it can even return a zero or n values.

Try-catch block cannot be used in a function

In the procedure, an exception can be handled by the try-catch block.

We cannot use the transaction

We can use a transaction.

The function can have input parameters only

the procedure can have both input and output parameters

A function can be called from Procedure 

The procedure cannot be called from function.

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos