Basic grammar

[declare

— Definition]

begin

— Execution

[exception

— Exception handling part]

end;

Where, the definition section begins with DECLARE, which is optional; The execution section begins with BEGIN, which is required

The exception section starts with Exception, which is optional. End is the end tag of a PL/SQL block.

 

Note that I am using SQL Plus installed with Oracle. Note the first line. Otherwise, the console does not output.

When finished, type/and press Enter.

Common variable types

char() varchar2() number() date;

Operators and expressions

 

 

 

If branch statement

If conditions then

Execute statement;

Elsif conditions then

Execute statement;

else

Execute statement;

end if;

“Then” is the same as if else if else in Java. Looks so disgusting syntax) remember end if; At the end

 

Remember to use “THEN” for all branches except else

A case statement

 

The case condition

When value then executes the statement

When value then executes the statement

.

Else execution statement

end;

 

 

Case can have a return value.

 

 

Assign the result of case to B; However, if we make case have a return value, it cannot be end case after the end of the case statement; It can only be end;

Looping statements

The basic cycle

loop

The executive body

Exit when condition;

end loop;

Attention! This way of writing it, the executor will definitely execute it once. The condition in exit is to stop the loop.

 

 

 

 

The program is executed from the top down.

The while loop

Conditions of the while loop

The loop body

end loop;

 

 

The for loop

For is assigned to in [reverse] start.. The end of the loop

The loop body

end loop;

 

 

You can see that the order in which the for loop is executed determines the start and end conditions. Satisfies assignment to i. Executes the body of the loop and then evaluates again.

The I in the for loop can be undeclared. Start and end conditions can also be variables, but only of type number

 

 

But if the assigned variable does not exist. You cannot use the variable after the loop call ends.

 

 

Reverse does ++ to —

Goto statement A very destructive statement

Goto jumps to the defined tag. Set the symbol of the tag to << tag >>

 

null

Null is very special. First, two null’s are not equal. Null itself is not equal to null

 

 

 

The composite variable

A standard variable can only hold a single value, and its counterpart is a compound variable. Compound variables can combine multiple values of different data types

Stored in the same cell.

% type variable

This variable is of indefinite type. The exact type of a variable is the same as the type of the table field assigned to it.

Use the SELECT INTO statement to assign the queried value to a variable; But be careful with the %type assignment

You must ensure that the assignment results in a single row and column.

 

 

The % rowtype variable

% rowType declares a variable representing a row of records (an object) to which you assign a table data structure to variable X