This is a translation reference to convert the Member Functions of the Oracle Create Type Statements (UDT's) to Snowflake
SnowConvert still does not recognize type member functions nor type body definitions. This page is only used as a future reference for translation.
Description
Like other Class definitions, Oracle's TYPE can implement methods to expose behaviors based on its attributes. MEMBER FUCTION will be transformed to Snowflake's Stored Procedures, to maintain functional equivalence due to limitations.
Since functions are being transformed into procedures, the transformation reference for PL/SQL also applies here.
Sample Source Patterns
Inserts for Simple square() member function
The next data will be inserted inside the table before querying the select. Please note these Inserts currently need to be manually migrated into Snowflake.
Oracle
INSERT INTO table_member_function_demo(column1) VALUES(type_member_function_demo(5));
Snowflake
INSERT INTO table_member_function_demo (column1)SELECT OBJECT_CONSTRUCT('a1', 5);
Simple square() member function
Oracle
-- TYPE DECLARATIONCREATETYPEtype_member_function_demoASOBJECT ( a1 NUMBER , MEMBER FUNCTION get_square RETURNNUMBER );/-- TYPE BODY DECLARATIONCREATETYPEBODY type_member_function_demo IS MEMBER FUNCTION get_squareRETURNNUMBERIS x NUMBER;BEGINSELECT c.column1.a1*c.column1.a1 INTO xFROM table_member_function_demo c;RETURN (x);END;END;/-- TABLECREATETABLEtable_member_function_demo(column1 type_member_function_demo);/-- QUERYING DATASELECT t.column1.get_square() FROM table_member_function_demo t;/
-- TYPE DECLARATION--CREATE TYPE type_member_function_demo AS OBJECT -- ( a1 NUMBER -- , MEMBER FUNCTION get_square RETURN NUMBER-- );--/-- TYPE BODY DECLARATION--CREATE TYPE BODY type_member_function_demo IS-- MEMBER FUNCTION get_square-- RETURN NUMBER-- IS x NUMBER;-- BEGIN-- SELECT c.column1.a1*c.column1.a1 INTO x-- FROM table_member_function_demo c;-- RETURN (x);-- END;--END;--/-- STORED PROCEDURE DECLARATIONCREATE OR REPLACEFUNCTIONget_square()RETURNSNUMBERAS$$SELECT c.column1:a1::NUMBER* c.column1:a1::NUMBERFROM table_member_function_demo c$$;-- TABLECREATETABLEtable_member_function_demo(column1 VARIANT);-- QUERYING DATASELECT get_square()