Record Type Definition

This is a translation reference to convert the Oracle Record Declaration to Snowflake

circle-info

Important Notice: Migration of Documentation Website

Please be advised that our documentation website is currently undergoing a migration to a new platform. To ensure you have access to the most up-to-date information, we kindly request that you visit our new documentation website located at:

Official Snowflake Snowconvert Documentationarrow-up-right

For any immediate assistance or if you encounter any issues, please contact our support team at [email protected]envelope.

Thank you for your understanding.

circle-exclamation
circle-info

Some parts in the output code are omitted for clarity reasons.

Description

A record variable is a composite variable whose internal components, called fields, can have different data types. The value of a record variable and the values of its fields can change.

You reference an entire record variable by its name. You reference a record field with the syntax record.field.

You can create a record variable in any of these ways:

  • Define a record type and then declare a variable of that type.

  • Use %ROWTYPE to declare a record variable that represents either a full or partial row of a database table or view.

  • Use %TYPE to declare a record variable of the same type as a previously declared record variable.

(Oracle PL/SQL Language Reference RECORD VARIABLESarrow-up-right)

For the translation, the type definition is replaced by an OBJECT Semi-structured Data Typearrow-up-right and then its usages are changed accordingly across any operations.

In order to define a Record type, the syntax is as follows:

To declare a variable of this type:

Sample Source Patterns

circle-info

Some parts in the output code are omitted for clarity reasons.

Record initialization and assignment

This sample attempts to insert two new rows using a record variable which is reassigned mid-procedure.

Oracle

Snowflake

Notice how the reassignments are replaced by an OBJECT_INSERT that updates if the column already exists, and how the VALUES clause is replaced by a SELECT.

%ROWTYPE Record and Values Record

Since the operations are the ones that define the structure, these definitions can be replaced by an OBJECT datatype, but the values of the record need to be decomposed as inserting the record "as-is" is not supported.

Oracle

Snowflake

Please note finally how the OBJECT variable needs to be initialized in order to add the information to it.

Fetching data into a Record

Oracle

Snowflake

Please note the additional OBJECT_CONSTRUCT in the Cursor definition, this is what allows to extract an OBJECT, which then can be used to seamlessly migrate the FETCH statement.

Assigning a Record Variable in a SELECT INTO

This transformation consists in taking advantage of the OBJECT_CONTRUCT function to initialize the record using the SELECT columns as the arguments.

Sample auxiliary code

Oracle

Snowflake

Known Issues

1. The following functionalities are currently not being converted:

  • Fetching data into a Record.

  • Nested records (Records inside records).

  • Collections inside records.

  1. SSC-EWI-0036: Data type converted to another data type.

  2. SSC-EWI-0056: Create Type Not Supported

  3. SSC-FDM-0006: Number type column may not behave similarly in Snowflake.

  4. SSC-FDM-OR0042: Date Type Transformed To Timestamp Has A Different Behavior.

  5. SSC-FDM-OR0035: DBMS_OUTPUT.PUTLINE check UDF implementation.

  6. SSC-PRF-0003: Fetch inside a loop is considered a complex pattern, this could degrade Snowflake performance.

Last updated