Basic Structure

Structure

A PL/SQL block can contain a sub-block which can be placed in any section. The following describes the architecture of a PL/SQL block:

  • DECLARE: declares variables, types, cursors, and regional stored procedures and functions used in the PL/SQL block.

    DECLARE
    

    NOTE:
    This part is optional if no variable needs to be declared.

    • An anonymous block may omit the DECLARE keyword if no variable needs to be declared.
    • For a stored procedure, AS is used, which is equivalent to DECLARE. The AS keyword must be reserved even if there is no variable declaration part.
  • EXECUTION: specifies procedure and SQL statements. It is the main part of a program. Mandatory.

    BEGIN
    
  • Exception part: processes errors. Optional.

    EXCEPTION
    
  • End

    END;
    /
    

    NOTICE:
    You are not allowed to use consecutive tabs in the PL/SQL block because they may result in an exception when the gsql tool is executed with the -r parameter specified.

Category

PL/SQL blocks are classified into the following types:

  • Anonymous block: a dynamic block that can be executed only for once. For details about the syntax, see Figure 1.
  • Subprogram: a stored procedure, function, operator, or packages stored in a database. A subprogram created in a database can be called by other programs.
Feedback
编组 3备份
    openGauss 2024-11-22 00:52:56
    cancel