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