---
title: "PL/SQL Sub-program Vs. Stored Procedure: Best Examples"
description: "A procedure also called subprogram explained how to use and call it in Oracle database"
url: https://srinimf.com/2022/06/13/how-to-use-subprogram-in-oracle-database/
date: 2022-06-13
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2022/06/pexels-photo-196667.jpeg?fit=1880%2C1253&ssl=1
categories: ["Oracle"]
tags: ["Oracle Procedures"]
type: post
lang: en
---

# PL/SQL Sub-program Vs. Stored Procedure: Best Examples

Here’s a way [to write](https://srinimf.com/2017/07/21/the-way-for-db2-stored-procedure-to-write-in-java/) procedures/functions in PL/SQL. In Oracle, named PL[SQL procedures](https://srinimf.com/2022/01/15/named-vs-unnamed-pl-sql-procedures/)/functions are called sub-programs. The difference between these procedures do an action, whereas functions compute a value.

IN THIS PAGE

1. [What’s Sub-program?](https://srinimf.com/2022/06/13/how-to-use-subprogram-in-oracle-database/#what-s-sub-program)
2. [PLSQL Procedure /or Function](https://srinimf.com/2022/06/13/how-to-use-subprogram-in-oracle-database/#plsql-procedure-or-function)

## What’s Sub-program?

Like unnamed (anonymous) PL/SQL blocks, subprograms have three parts. These are a declarative part, an executable part, and an optional exception-handling part.

- The **declarative part** contains declarations of types, cursors, constants, variables, exceptions, and nested subprograms. These are local and cease to exist when you exit the subprogram.
- The **executable part** contains statements that assign values, control execution, and manipulate Oracle data.
- The **exception-handling part** contains exception handlers, which deal with exceptions raised during execution.

## PLSQL Procedure /or Function

Below you’ll find procedure named debit_account, which debits a bank account.

```
PROCEDURE debit_account (acct_id INTEGER, amount REAL) IS
 old_balance REAL;
 new_balance REAL;
 overdrawn EXCEPTION;
BEGIN
 SELECT bal INTO old_balance FROM accts
 WHERE acct_no = acct_id;
 new_balance := old_balance – amount;
 IF new_balance < 0 THEN
 RAISE overdrawn;
 ELSE
 UPDATE accts SET bal = new_balance WHERE acct_no = acct_id;
 END IF;
 EXCEPTION
 WHEN overdrawn THEN
 …
END debit_account;
```

**How it works**

When invoked, it accepts an account number and a debit amount. It uses the account number to select the account balance from the accts table. Then, it uses the debit amount to compute a new balance. If the new balance is less than zero, an exception is raised, otherwise, the bank account is updated.

Related

- [What is Package in Oracle PLSQL](https://srinimf.com/2012/07/21/sql-what-is-package/)DateJuly 21, 2012
- [The Usage of Each PL/SQL Block](https://srinimf.com/2014/08/12/oracle-plsql-step-by-step-guide/)DateAugust 12, 2014
- [Here is Logic to Write UDF to Check Input is Number or not](https://srinimf.com/2021/12/06/function-that-checks-input-value-is-number-or-not/)DateDecember 6, 2021

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2022%2F06%2F13%2Fhow-to-use-subprogram-in-oracle-database%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2022%2F06%2Fpexels-photo-196667.jpeg%3Ffit%3D1200%252C800%26ssl%3D1&description=PL%2FSQL%20Sub-program%20Vs.%20Stored%20Procedure%3A%20Best%20Examples)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2022/06/13/how-to-use-subprogram-in-oracle-database/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2022/06/13/how-to-use-subprogram-in-oracle-database/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2022/06/13/how-to-use-subprogram-in-oracle-database/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2022/06/13/how-to-use-subprogram-in-oracle-database/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20PL%2FSQL%20Sub-program%20Vs.%20Stored%20Procedure%3A%20Best%20Examples&body=https%3A%2F%2Fsrinimf.com%2F2022%2F06%2F13%2Fhow-to-use-subprogram-in-oracle-database%2F&share=email)
-

### Like this:

Like Loading…
