This article is about the current transformation of the output parameters and how their functionality is being emulated.
Description
An output parameter is a parameter whose value is passed out of the stored procedure/function module, back to the calling PL/SQL block. Since the output parameters are not supported by Snowflake Scripting, a solution has been implemented in order to emulate their functionality.
Sample Source Patterns
Sample auxiliary table
IN -> Oracle_01.sql
CREATE TABLE table01 (col1 NUMBER, col2 NUMBER);
OUT -> Oracle_01.sql
CREATE OR REPLACE TABLE table01 (col1 NUMBER(38, 18) /*** SSC-FDM-0006 - NUMBER TYPE COLUMN MAY NOT BEHAVE SIMILARLY IN SNOWFLAKE. ***/,col2 NUMBER(38, 18) /*** SSC-FDM-0006 - NUMBER TYPE COLUMN MAY NOT BEHAVE SIMILARLY IN SNOWFLAKE. ***/)COMMENT ='{"origin":"sf_sc","name":"snowconvert","version":{"major":1, "minor":0},{"attributes":{"component":"oracle"}}';
In the declaration, the OUT or IN OUT keywords are removed. The assignment is being emitted the same as the input but to emulate the functionality of the output parameter some statements are being added.
When a procedure with output parameters is being called into another one, some statements are added in order to get and assign the value(s) to the respective argument(s).
Single out parameter
Oracle
IN -> Oracle_02.sql
-- Procedure with output parameter declarationCREATE OR REPLACE PROCEDURE proc_with_single_output_parameters( param1 OUT NUMBER)ISBEGIN param1 :=123;END;-- Procedure with output parameter being calledCREATE OR REPLACE PROCEDURE proc_calling_proc_with_single_output_parametersIS var1 NUMBER;BEGIN proc_with_single_output_parameters(var1); INSERT INTO TABLE01 VALUES(var1, -1);END;
Snowflake Scripting
OUT -> Oracle_02.sql
-- Procedure with output parameter declarationCREATE OR REPLACE PROCEDURE proc_with_single_output_parameters (param1 NUMBER(38, 18))RETURNS VARIANTLANGUAGE SQLCOMMENT ='{"origin":"sf_sc","name":"snowconvert","version":{"major":1, "minor":0},{"attributes":{"component":"oracle"}}'EXECUTE AS CALLERAS$$ BEGIN param1 :=123; RETURN param1; END;$$;-- Procedure with output parameter being calledCREATE OR REPLACE PROCEDURE proc_calling_proc_with_single_output_parameters ()RETURNS VARCHARLANGUAGE SQLCOMMENT ='{"origin":"sf_sc","name":"snowconvert","version":{"major":1, "minor":0},{"attributes":{"component":"oracle"}}'EXECUTE AS CALLERAS$$ DECLARE var1 NUMBER(38, 18); call_results VARIANT; BEGIN call_results := ( CALL proc_with_single_output_parameters(:var1) ); var1 := :call_results; INSERT INTO TABLE01VALUES(:var1, -1); END;$$;
Multiple out parameter
Oracle
IN -> Oracle_03.sql
-- Procedure with output parameters declarationCREATE OR REPLACE PROCEDURE proc_with_multiple_output_parameters( param1 OUT NUMBER, param2 IN OUT NUMBER)ISBEGIN param1 :=123; param2 :=456;END;-- Procedure with output parameters being calledCREATE OR REPLACE PROCEDURE proc_calling_proc_with_multiple_output_parametersIS var1 NUMBER; var2 NUMBER;BEGIN proc_with_multiple_output_parameters(var1, var2); INSERT INTO TABLE01 VALUES(var1, var2);END;
Snowflake Scripting
OUT -> Oracle_03.sql
-- Procedure with output parameters declarationCREATE OR REPLACE PROCEDURE proc_with_multiple_output_parameters (param1 NUMBER(38, 18), param2 NUMBER(38, 18))RETURNS VARIANTLANGUAGE SQLCOMMENT ='{"origin":"sf_sc","name":"snowconvert","version":{"major":1, "minor":0},{"attributes":{"component":"oracle"}}'EXECUTE AS CALLERAS$$ BEGIN param1 :=123; param2 :=456; RETURN OBJECT_CONSTRUCT('param1', :param1, 'param2', :param2); END;$$;-- Procedure with output parameters being called--** SSC-FDM-0007 - MISSING DEPENDENT OBJECT "TABLE01" **CREATE OR REPLACE PROCEDURE proc_calling_proc_with_multiple_output_parameters ()RETURNS VARCHARLANGUAGE SQLCOMMENT ='{"origin":"sf_sc","name":"snowconvert","version":{"major":1, "minor":0},{"attributes":{"component":"oracle"}}'EXECUTE AS CALLERAS$$ DECLARE var1 NUMBER(38, 18); var2 NUMBER(38, 18); call_results VARIANT; BEGIN call_results := ( CALL proc_with_multiple_output_parameters(:var1, :var2) ); var1 := :call_results:param1; var2 := :call_results:param2; INSERT INTO TABLE01VALUES(:var1, :var2); END;$$;
In order to check that the functionality is being emulated correctly the following query is going to execute the procedure and a SELECT from the table mentioned before.
Oracle
IN -> Oracle_04.sql
CALL proc_with_single_output_parameters();CALL proc_with_multiple_output_parameters();SELECT * FROM table01;
COL1|COL2
----+----
123 |-1
123 |456
Snowflake Scripting
OUT -> Oracle_04.sql
CALL proc_with_single_output_parameters();CALL proc_with_multiple_output_parameters();SELECT * FROM table01;
when the output parameter is a customer type, the process is similar to a regular data type.
Oracle
IN -> Oracle_05.sql
CREATE OR REPLACE PROCEDURE procedure_udtype_out_params ( p_employee_id NUMBER, p_address OUT address_type)ASBEGIN-- Retrieve the employee's address based on the employee ID. SELECT home_address INTO p_address FROM employees WHERE employee_id = p_employee_id;END;
Snowflake Scripting
OUT -> Oracle_05.sql
CREATE OR REPLACE PROCEDURE procedure_udtype_out_params (p_employee_id NUMBER(38, 18), p_address VARIANT /*** SSC-FDM-0015 - REFERENCED CUSTOM TYPE 'address_type' IN QUERY NOT FOUND, USAGES MAY BE AFFECTED ***/)RETURNS VARIANTLANGUAGE SQLCOMMENT ='{"origin":"sf_sc","name":"snowconvert","version":{"major":1, "minor":0},{"attributes":{"component":"oracle"}}'EXECUTE AS CALLERAS$$ BEGIN-- Retrieve the employee's address based on the employee ID. SELECT home_address INTO :p_address FROM employees WHERE employee_id = :p_employee_id; RETURN p_address; END;$$;
Known Issues
1. Procedures with output parameters inside packages may not work correctly
Currently, there is an issue collecting the semantic information of procedures that reside inside packages, which is why the transformation for output parameters may work partially or not work at all. There is already a work in progress to resolve this issue.
2. Some data types may not work properly
As seen in the transformation, when retrieving the value from the called procedures, an implicit cast is performed from VARIANT to the type specified by the variable. Since there are a lot of possible data types, some casts may fail or contain different data.
Related EWIs
SSC-FDM-0006: Number type column may not behave similarly in Snowflake.