ACTION

DEFINE ACTION

Specifies a named action that is a parameterizable block of multiple top-level expressions.

Syntax

  1. DEFINE ACTION: action definition.
  2. Action name that will be used to access the defined action further in the query.
  3. The values of parameter names are listed in parentheses.
  4. AS keyword.
  5. List of top-level expressions.
  6. END DEFINE: The marker of the last expression inside the action.

One or more of the last parameters can be marked with a question mark ? as optional. If they are omitted during the call, they will be assigned the NULL value.

DO

Executes an ACTION with the specified parameters.

Syntax

  1. DO: Executing an action.
  2. The named expression for which the action is defined.
  3. The values to be used as parameters are listed in parentheses.

EMPTY_ACTION: An action that does nothing.

Example

  1. DEFINE ACTION $hello_world($name, $suffix?) AS
  2. $name = $name ?? ($suffix ?? "world");
  3. SELECT "Hello, " || $name || "!";
  4. END DEFINE;
  5. DO EMPTY_ACTION();
  6. DO $hello_world(NULL);
  7. DO $hello_world("John");
  8. DO $hello_world(NULL, "Earth");

ACTION - 图1

BEGIN .. END DO

Performing an action without declaring it (anonymous action).

Syntax

  1. BEGIN.
  2. List of top-level expressions.
  3. END DO.

An anonymous action can’t include any parameters.

Example

  1. DO BEGIN
  2. SELECT 1;
  3. SELECT 2 -- here and in the previous example, you might omit ';' before END
  4. END DO

ACTION - 图2