Collection Methods

This is a translation reference to convert the Oracle Collection Methods to Snowflake

Description

A collection method is a PL/SQL subprogram—either a function that returns information about a collection or a procedure that operates on a collection. Collection methods make collections easier to use and your applications easier to maintain.

(Oracle PL/SQL Language Reference COLLECTION METHODS)

Some of these methods can be mapped to native Snowflake semi-structured operations. The ones that can't or have differences will be mapped to a UDF implementation.

Current SnowConvert Support

The next table shows a summary of the current support provided by the SnowConvert tool. Please keep into account that translations may still not be final, and more work may be needed.

Method
Current recognition status
Current translation status
Mapped to

Not Recognized.

Not Translated.

UDF

Not Recognized.

Not Translated.

UDF (To be defined)

Not Recognized.

Not Translated.

UDF

Not Recognized.

Not Translated.

Not Recognized.

Not Translated.

UDF

Not Recognized.

Not Translated.

UDF

Not Recognized.

Not Translated.

Not Recognized.

Not Translated.

Not Supported.

Not Recognized.

Not Translated.

UDF (To be defined)

Not Recognized.

Not Translated.

UDF (To be defined)

Sample Source Patterns

COUNT

This method returns the count of "non-undefined" (not to be confused with null) elements within a collection (nested tables can become sparse leaving these elements in between). In associative arrays, it returns the number of keys in the array.

Oracle

Snowflake

The snowflake equivalent is the ARRAY_SIZE method.

EXISTS

This method returns true if the given element is contained within the collection. In associative arrays, it tests if the key is contained.

Oracle

Snowflake

The snowflake equivalent is the ARRAY_CONTAINS method. Note that, when using Varchar elements, casting to Variant is necessary.

FIRST/LAST

These two methods return the First/Last element of the collection, respectively. If the collection is empty it returns null. This operation is mapped to a UDF, which will be added in further revisions.

Oracle

Snowflake

DELETE

This method is used to remove elements from a Collection. It has three possible variants:

  • .DELETE removes all elements.

  • .DELETE(n) removes the element whose index matches 'n'.

  • .DELETE(n, m) removes in the indexes from 'n' through 'm'.

In Oracle, using this operation on Nested Tables causes it to have "undefined" elements within it due to them being sparse.

Oracle

For the sake of simplicity, this sample only checks on the number of elements but may be modified to display the contents of each collection.

Snowflake

Snowflake does not support deletions from an existing ARRAY and for this reason, the only offered workaround is to rebuild a new ARRAY depending on the original parameters of the DELETE.

Note that a UDF was added to implement the functionality for the update of the element.

This UDF will be added in later revisions.

EXTEND

This method is used to append new elements to a Nested Table or a Varray. It has three possible variants:

  • .EXTEND inserts a null element.

  • .EXTEND(n) inserts 'n' null elements.

  • .EXTEND(n, i) inserts 'n' copies of the element at 'i'.

Oracle

Snowflake

Note that a UDF was added to implement the functionality for the update of the element.

This UDF will be added in later revisions.

TRIM

This method is used to remove the last elements from a Nested Table or a Varray. It has two possible variants:

  • .TRIM removes the last element.

  • .TRIM(n) removes the last 'n' elements.

This functionality may be implemented using ARRAY_SLICE

Oracle

LIMIT

This method returns the maximum limit of a Varray.

Oracle

PRIOR/NEXT

This method returns the prior/next index, given an index. If there is not a prior/next then it returns null. It is most frequently used to traverse a collection.

Oracle

Known Issues

1. Limit method is not supported in Snowflake

Snowflake does not have support for limited-space varrays. For this reason, this method is not supported.

  1. MSCEWI1058: Functionality is not currently supported by Snowflake Scripting.

Last updated

Was this helpful?