Variables of Oracle PL/SQL Programming

Source: Internet
Author: User
Tags scalar

Note:

The tables used in the following test cases are derived from the Scott scenario, before use, make sure that the user is unlocked.

1. Introduction

As with most programming languages, when you write a PL/SQL program, you can define constants and variables that are included in the PL/SQL program:

A, scalar type (scalar)

B, composite type (Composite)

C, reference type (Refrence)

D, LOB (large object) type

Here is a brief introduction

2. Scalar type---Common type

When writing a PL/SQL statement, if you need to use a variable, you need to define the variable in the definition section. The syntax for defining a variable constant in PL/SQL is as follows:

identifier [constant] datatype [NOT NULL] [: =| default expr]

Identifier: Name

Constant: Specifies a constant and needs to specify its initial value, and its value cannot be changed

DataType: Data type

Not NULL: The value of the specified variable cannot be empty

: = Specifies the initial value for a variable or constant

Defalut: Used to specify initial values

Expr: a PL/SQL expression that specifies an initial value, but a literal value, other variable, or function

2.1. Examples of scalar definitions

Defines a variable-length string

V_name VARCHAR2 (10);

Defines a decimal range -9999.99~9999.99

V_sal Number (6,2)

Define a decimal and give the initial value 6.6 Note:: = is a variable assignment number for PL/SQL

V_num Number (6.2): =6.6

Define data for a date type

V_date date;

Set a Boolean variable that cannot be null and the initial value is false;

V_bool Boolean NOT null Defalut false;

Note: The use of scalar in PL/SQL and assigning an initial value to it differs from other programming languages by adding ":" Before the equals sign.

2.2, the use of scalar cases

Enter an employee number that shows the employee's name, salary, and personal income tax (tax rate is 0.03), and the code is as follows:

Variables of Oracle PL/SQL Programming

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.