VARIABLES

Translation spec for Package Variables

Description

PACKAGE VARIABLES can be declared either in the package declaration or in the PACKAGE BODY. Due to its behavior, these variables are converted into Snowflake session variables so each usage or assignment is translated to its equivalent in Snowflake.

variable datatype [ [ NOT NULL] {:= | DEFAULT} expression ] ;

Sample Source Patterns

Sample auxiliary code

create table table1(id number);

Variable declaration

Oracle

CREATE OR REPLACE PACKAGE PKG1 AS
	package_variable NUMBER:= 100;
END PKG1;

Snowflake Scripting

CREATE SCHEMA IF NOT EXISTS SCHEMA1_PKG1;

SET "SCHEMA1_PKG1.PACKAGE_VARIABLE" = '' || (100);

Variable Usage

Package variable usages are transformed into the Snowflake GETVARIABLE function which accesses the current value of a session variable. An explicit cast is added to the original variable data type in order to maintain the functional equivalence in the operations where these variables are used.

Oracle

Snowflake

Variable regular assignment

When a package variable is assigned using the := operator, the assignation is replaced by a SnowConvert UDF called UPDATE_PACKAGE_VARIABLE_STATE which is an abstraction of the Snowflake SETVARIABLE function.

Oracle

Snowflake

Variable assignment as an output argument

When a package variable is used as an output argument a new variable is declared inside the procedure, this variable will catch the output argument value of the procedure, and then the variable will be used to update the session variable which refers to the package variable using the UPDATE_PACKAGE_VARIABLE_STATE mentioned above. For more information check de output parameters transformation.

Oracle

Snowflake

Known Issues

No issues were found.

  1. MSCEWI1082: Auto-Generated code in order to support output parameters in Snowflake Scripting.

  2. MSCEWI3122: Package Variable Assignment transformation.

Last updated

Was this helpful?