Help Center> GaussDB> Centralized_3.x> Stored Procedure> Dynamic Statements> Dynamically Calling Anonymous Blocks
Updated on 2024-05-07 GMT+08:00

Dynamically Calling Anonymous Blocks

This section describes how to execute anonymous blocks in dynamic statements. Append IN and OUT behind the EXECUTE IMMEDIATE...USING statement to input and output parameters.

Syntax

Figure 1 shows the syntax diagram.

Figure 1 call_anonymous_block::=

Figure 2 shows the syntax diagram for using_clause.

Figure 2 using_clause::=

The above syntax diagram is explained as follows:

  • The execute part of an anonymous block starts with a BEGIN statement, has a break with an END statement, and ends with a semicolon (;).
  • USING [IN|OUT|IN OUT]bind_argument: specifies where the variable passed to the stored procedure parameter value is stored. The modifiers in front of bind_argument and of the corresponding parameter are the same.
  • The input and output parameters in the middle of an anonymous block are designated by placeholders. The numbers of the placeholders and parameters are the same. The sequences of the parameters corresponding to the placeholders and the USING parameters are the same.
  • Currently in GaussDB, when dynamic statements call anonymous blocks, placeholders cannot be used to pass input and output parameters in an EXCEPTION statement.
  • Overloaded functions with placeholders cannot be called.
  • The PERFORM keyword cannot be used to invoke a stored procedure when parameters are bound.
  • Variables declared in an anonymous block and binding parameters cannot be used in the same statement at the same time.
  • Only SQL statements invoked in anonymous blocks and stored procedures with OUT/INOUT parameters can be bound to parameters. For example, expressions and cursors are used in anonymous blocks, and dynamic statements are invoked in nested mode in anonymous blocks.