PL/SQL Programming   «Prev  Next»

Lesson 1

Declaring PL/SQL Variables in Oracle

This course starts off by introducing you to PL/SQL and the tools that you can use to build your queries with PL/SQL. Then you will
  1. learn about the different variable types that are used within PL/SQL.
  2. enhance your knowledge of non-PL/SQL bind and host variables.
  3. learn about the DBMS_OUTPUT.PUT_LINE
  4. review some of the recommended naming conventions for application code.

Example 1:
int BookCount;
...
select COUNT(*) into :BookCount from BOOKSHELF;
:= (Set Equal To)

PL/SQL variable FORMAT

variable := expression
DESCRIPTION: The PL/SQL variable is set equal to the expression, which may be a constant, NULL, or a calculation with other variables, literals, and PL/SQL functions.
Example 2:
Extension := Quantity * Price;
Title := 'BARBERS WHO SHAVE THEMSELVES';
Name := NULL;

Module objectives

By the end of this module, you will know how to:
  1. Define the term PL/SQL and describe some of the common tools used to develop PL/SQL
  2. Identify different types of variables
  3. Identify variable datatypes
  4. Use the non-PL/SQL bind and host variables to manipulate data within SQL*Plus
  5. Use the DBMS_OUTPUT.PUT_LINE package procedure[1] to display values to the SQL*Plus screen
  6. Illustrate the importance of naming conventions for application code
In the next lesson, we will begin by defining what PL/SQL is.

Oracle PL/SQL Best Practices

Using Variables

Variables are memory regions used in a PL/SQL block to hold data. They are defined in the DECLARATION section of the block, where they are assigned a specific data type and are often initialized with a value. The syntax for declaring a variable is
variable_name [CONSTANT] type [NOT NULL] [:= value];
Variable_name is the name you give to the variable. Type is the data type the variable needs to support. Value is used to initialize a variable. The following example shows some different ways to declare variables:

DECLARE
v_first_name VARCHAR2(50);
v_author_count PLS_INTEGER := 0;
v_date DATE NOT NULL DEFAULT SYSDATE;
...

The greater the number of entangled particles, the greater the probablity that the entire system as a whole will collapse at any moment.
[1] package procedure: to display the output to your screen.