COMPOUND STATEMENTS

This section is a translation specification for the compound statements

General description

The basic unit of a PL/SQL source program is the block, which groups related declarations and statements.

A PL/SQL block is defined by the keywords DECLARE, BEGIN, EXCEPTION, and END. These keywords divide the block into a declarative part, an executable part, and an exception-handling part. Only the executable part is required. (PL/SQL Anonymous Blocks)

The BEGIN...END block in Oracle can have the following characteristics:

  1. Be nested.

  2. Contain the DECLARE statement for variables.

  3. Group multiple SQL or PL/SQL statements.

Oracle syntax

[DECLARE <Variable declaration>]
BEGIN
  <Executable statements>
[EXCEPTION <Exception handler>]
END

Snowflake syntax

BEGIN
    <statement>;
    [ <statement>; ... ]
[ EXCEPTION <exception_handler> ]
END;

In Snowflake, a BEGIN/END block can be the top-level construct inside an anonymous block (Snowflake documentation).

Sample Source Patterns

1. IF-ELSE block

Review the following documentation about IF statements to learn more: SnowConvert IF statements translation and Snowflake IF statement documentation

Oracle

Snowflake

2. CASE statement

For more information, review the following documentation: SnowConvert CASE statement documentation and Snowflake CASE documentation

Oracle

Snowflake

3. LOOP statements

For more information review the following documentation: SnowConvert FOR LOOP and Snowflake LOOP documentation and FOR documentation.

Oracle

Snowflake

4. Procedure call and OUTPUT parameters

Anonymous block in Oracle may have calls to procedures. Furthermore, the following documentation may be useful: SnowConvert Procedure documentation.

The following example uses the OUT parameters, the information about the current transformation can be found here: SnowConvert OUTPUT Parameters

Oracle

Snowflake

5. Alter session

For more information, review the following documentation: Alter session documentation.

Notice that in Oracle, the block BEGIN...END should use the EXECUTE IMMEDIATE statement to run alter session statements.

Oracle

Snowflake

6. Cursors

The following example displays the usage of a cursor inside a BEGIN...END block. Review the following documentation to learn more: Cursor documentation.

Oracle

Snowflake

7. Select statements

For more information review the following documentation: Select documentation.

Oracle

Snowflake

8. Join Statements

For more information review the following documentation: Joins documentation.

Oracle

Snowflake

9. Exception handling

Oracle

Snowflake

Known issues

  1. Unsupported GOTO statements in Oracle. Review this page.

  2. Exceptions that use GOTO statements may be affected too.

  3. Cursor functionality may be adapted under current restrictions on translations.

Last updated

Was this helpful?