PL/SQL Programming _ variables

Source: Internet
Author: User

Variables and data types can be defined in a PL/SQL block, which makes the PL/SQL block more flexible with data processing.

The definition of variables and types is placed in the variable Declarations section of the PL/SQL block.

Definition and use of variables

There are two types of definitions for variables, namely:
Variable name TYPE [constraint][default default]
Variable name TYPE [constraint][:= initial value]
The part that is delimited by square brackets is optional.

Constraints are used to specify the conditions that a variable must satisfy, such as a "notnull" constraint that specifies that a variable cannot be null, so that the variable is defined with an initial value or a default value.
Variable names are subject to certain naming conventions.

Variable names must begin with a letter, contain numbers, letters, and underscores to reverse the $, # notation, and cannot exceed 30 characters in length and cannot be the same as the Oracle keyword.
Variable names are not related to capitalization.
The type of a variable can be either a data type provided by PL/SQL or a user-defined type.

Basic Data type description

Binary integer integer type data (note: binary binary)

number[(precision, fractional)] can represent integers and floating-point numbers

CHAR [(maximum length)] string, up to 32 767 bytes in length

Long string

Long raw-to-

VARCHAR2 (maximum length) consistent with VARCHAR2 in the database

DATE and date-in the database

Boolean evaluates to True and False

In addition to the basic types described above, PL/SQL also defines some subtypes .

These basic data types can be used in a PL/SQL block, or their subtypes, but the final type of the data is still its base type.

Child Type Parent Type description

Natural and Naturaln BINARY INTEGER Natural number, where the latter cannot be empty
Positive and Positiven BINARY integer positive integer, where the latter cannot be null
Signtype Binary INTEGER values are 11, 0, I
int and integer BINARY integer integer type data
DEC, DECIMAL NUMERIC BINARY INTEGER equivalent to number, provides ANSI compatibility
FLOAT Binary INTEGER 126-bit binary floating-point number
REAL Binary INTEGER 63-bit binary floating-point number
CHARACTER Char is equivalent to char and provides ANSI compatibility
STRING VARCHAR2 is equivalent to VARCHAR2 and provides ANSI compatibility
VARCHAR VARCHAR2 and VARCHAR2 equivalence

Variables can be defined by specifying a default value or an initial value, which can be assigned during the operation of a PL/SQL block.

The format of the assignment is:

Variable name: = Expression











PL/SQL Programming _ variables

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.