Oracle PL/SQL - PL SQL Introduction Variable Declarations

Introduction

A variable declaration includes the name and data type of the variable.

For most data types, a variable declaration can also have an initial value.

The variable name must be a valid user-defined identifier.

The data type can be any PL/SQL data type.

The PL/SQL data types include the SQL data types.

A data type is either scalar which has no internal components or composite which can have internal components.

The following code declares several variables with scalar data types.

Demo

SQL>
SQL> DECLARE--  w w w . j av  a  2  s  . co m
  2    part_number       NUMBER(6);     -- SQL data type
  3    part_name         VARCHAR2(20);  -- SQL data type
  4    in_stock          BOOLEAN;       -- PL/SQL-only data type
  5    part_price        NUMBER(6,2);   -- SQL data type
  6    part_description  VARCHAR2(50);  -- SQL data type
  7  BEGIN
  8    DBMS_OUTPUT.PUT_LINE(part_number);
  9    DBMS_OUTPUT.PUT_LINE(part_name);
 10    DBMS_OUTPUT.PUT_LINE(in_stock);
 11    DBMS_OUTPUT.PUT_LINE(part_price);
 12    DBMS_OUTPUT.PUT_LINE(part_description);
 13    NULL;
 14  END;
 15   /
  DBMS_OUTPUT.PUT_LINE(in_stock);
  *
ERROR at line 10:
ORA-06550: line 10, column 3:
PLS-00306: wrong number or types of arguments in
call to 'PUT_LINE'
ORA-06550: line 10, column 3:
PL/SQL: Statement ignored


SQL>

Related Topics

Quiz