1. Variable
2. Constant
3. Basic program Structure and statement
Pl/sql can reside in both Oracle database servers and Oracle development tools environments. In both environments, the Pl/sql engine accepts any pl/sql block and subroutine as input, and the engine executes a procedure statement that sends the SQL statement to the SQL statement executor executed by the Oracle server.
1, Pl/sql variable
(1) The declaration of the variable:
Variables are usually defined in the Declarations section of a pl/sql block, and each variable has a specific type.
The basic format for a variable definition is:
< variable name > < data type >[(width):=< initial value
For example, define a number type variable named Countnum, with an initial value of 1, which can be written as follows:
Countnum number: = 1;
--The basic naming rules for variables are as follows:
--a. Variable names must begin with a letter
--b. Variable length not exceeding 30 characters
--c. Cannot have spaces in variable names
(2) The properties of the variable
% is used to represent property prompts.
%type property. The%type property provides properties for variables and database columns. This property is very convenient, assuming that there is a table A, there is a field B, now to define a variable C, it needs its data type and field B, this time we can not know the data type of B, the direct use of b%type can be, such as: C B%type.
%rowtype property. This property provides a data type that represents one row of records in a table. With it, we can easily use a variable to represent a row in a cursor, such as Cursorrecord Cursorname%rowtype, where Cursorrecord represents a variable name on one row of the cursor, Cursorname represents the name of the corresponding cursor, using% RowType can be taken to a row of record types, so that later in the data, you can directly use the
Fetch cursorname into Cursorrecord. Sample code:
DECLARE CURSOR modulecursor is
select * from T_module;
Modulerecord Modulecursor%rowtype;
Begin
Open modulecursor;
Fetch modulecursor into Modulerecord;
While Modulecursor%found
loop
dbms_output.put_line (Modulerecord.name | | '**********************');
Fetch modulecursor into Modulerecord;
End Loop;
Close modulecursor;
End