doc-exports/docs/dws/dev/dws_04_0520.html
Lu, Huayi a24ca60074 DWS DEVELOPER 811 version
Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com>
Co-authored-by: Lu, Huayi <luhuayi@huawei.com>
Co-committed-by: Lu, Huayi <luhuayi@huawei.com>
2023-01-19 13:37:49 +00:00

4.5 KiB

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

    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: processes errors. Optional
    EXCEPTION
  • END
    END;
    /

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

Type

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.