What is the difference between a stored procedure and a function in PL/SQL?

1 Answers
Answered by suresh

PL/SQL Developer Interview Question

What is the difference between a stored procedure and a function in PL/SQL?

In PL/SQL, stored procedures and functions are both pieces of reusable code that can be called to perform specific tasks. However, there are key differences between the two:

Stored Procedure:

  • A stored procedure does not return a value. It is used to perform a set of actions or tasks.
  • Stored procedures can have input and output parameters.
  • Stored procedures can contain DML (Data Manipulation Language) and DDL (Data Definition Language) statements.
  • Stored procedures can be called independently or from within another SQL statement.

Function:

  • A function must return a single value. It is used to perform a specific computation and return the result.
  • Functions must have a return type specified in their definition.
  • Functions do not support DDL statements, only DML statements.
  • Functions can be used in SQL queries, WHERE clauses, and expressions.

In summary, stored procedures are used for performing tasks and actions, while functions are used for computations and returning values in PL/SQL.

Answer for Question: What is the difference between a stored procedure and a function in PL/SQL?