SnowConvert AI - Oracle - Create Type

This is a translation reference to convert Oracle Create Type Statements (UDTs) to snowflake

Description générale

SnowConvert translates many Oracle CREATE TYPE statements to Snowflake native user-defined types where the shape is supported—for example object types with attributes, VARRAY mapped to Snowflake ARRAY, and nested table types mapped to ARRAY of the element type. Unsupported options (subtype inheritance, member bodies, incomplete types, and others) are flagged with Oracle-specific EWIs; see Related EWIs and the issues reference.

L’une des fonctionnalités les plus importantes que propose le moteur de base de données Oracle est une approche orientée objet. PL/SQL offre des capacités au-delà des autres bases de données relationnelles sous la forme de OOP en utilisant des instructions de type Java sous forme de paquets, de fonctions, de tables et de types. Ce document couvre le type et la manière dont SnowConvert AI le résout, en restant conforme à la fonctionnalité.

Oracle prend en charge les spécifications suivantes :

  • Type de données abstrait (ADT) (y compris un type d’objet SQLJ).

  • Type de tableau variable autonome (varray).

  • Type de table imbriquée autonome.

  • Type d’objet incomplet.

Tout cela d’après les informations trouvées dans la documentation Oracle de l’instruction Create Type

CREATE [ OR REPLACE ] [ EDITIONABLE | NONEDITIONAL ] TYPE <type name>
[ <type source creation options> ]
[<type definition>]
[ <type properties> ]

Limitations

Snowflake supports native user-defined types (CREATE TYPE … AS OBJECT, ARRAY, etc.) as documented in the SQL data types overview. SnowConvert maps many Oracle type definitions to those native types. Patterns that still have no or partial mapping—such as subtype inheritance (UNDER), member methods and type bodies, table types, and incomplete forward declarations—may require manual redesign or are reported via EWIs (for example SSC-EWI-OR0139 through SSC-EWI-OR0142). Semi-structured Data Types remain relevant for legacy scenarios that still use VARIANT in converted code.

Vous trouverez ci-dessous les fonctions des types définis par l’utilisateur pour lesquelles NO propose une solution de contournement :

Sous-types : Hiérarchie des types

Ces instructions ne sont pas prises en charge dans Snowflake. SnowConvert AI les reconnaît uniquement, mais aucune traduction n’est proposée.

CREATE TYPE person_t AS OBJECT (name VARCHAR2(100), ssn NUMBER) 
   NOT FINAL;
/

CREATE TYPE employee_t UNDER person_t 
   (department_id NUMBER, salary NUMBER) 
   NOT FINAL;
/

CREATE TYPE part_time_emp_t UNDER employee_t (num_hrs NUMBER);
/

Propriétés de type

Il s’agit des options qui sont normalement utilisées lors de l’utilisation de OOP dans PL/SQL : Persistable, Instantiable et Final.

CREATE OR REPLACE TYPE type1 AS OBJECT () NOT FINAL NOT INSTANTIABLE NOT PERSISTABLE;
CREATE OR REPLACE TYPE type2 AS OBJECT () FINAL INSTANTIABLE PERSISTABLE;

Type de table imbriquée

Ces instructions ne sont pas prises en charge dans Snowflake. SnowConvert AI les reconnaît uniquement, mais aucune traduction n’est proposée.

CREATE TYPE textdoc_typ AS OBJECT
    ( document_typ      VARCHAR2(32)
    , formatted_doc     BLOB
    ) ;
/

CREATE TYPE textdoc_tab AS TABLE OF textdoc_typ;
/

Options de création du type de source

Ces options correspondent à des options personnalisées concernant l’accès et la requête du type.

CREATE TYPE type1 FORCE OID 'abc' SHARING = METADATA DEFAULT COLLATION schema1.collation ACCESSIBLE BY (schema1.unitaccesor) AS OBJECT ();
CREATE TYPE type2 FORCE OID 'abc' SHARING = NONE DEFAULT COLLATION collation ACCESSIBLE BY (PROCEDURE unitaccesor) AS OBJECT ();
CREATE TYPE type3 AUTHID CURRENT_USER AS OBJECT ();
CREATE TYPE type4 AUTHID DEFINER AS OBJECT ();

Solutions de contournement proposées

À propos de la définition des types

Pour la définition, la solution proposée consiste à créer un type de données semi-structurées pour imiter le type de données d’Oracle.

À propos de la fonction membre des types

Pour les fonctions membres contenant de la logique et DML, la solution de contournement proposée s’appuie sur des aides pour les traduire en procédures stockées.

Prise en charge actuelle par SnowConvert AI

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

Élément d’instruction de type

Statut de reconnaissance actuel

Statut actuel de la traduction

Solutions de contournement connues

Définitions de type d’objet

Reconnu.

Translated to Snowflake CREATE TYPE … AS OBJECT where supported.

Oui.

Définitions de sous-type

Reconnu.

Non traduit.

Non.

Définitions de type Array

Reconnu.

Translated to Snowflake CREATE TYPE … AS ARRAY (see SSC-FDM-0043).

Oui.

Définitions de tables imbriquées

Reconnu.

Translated to Snowflake ARRAY of element type where supported.

Limited.

Définitions des fonctions membres

Reconnu.

Non traduit.

Oui.

Problèmes connus

1. DML usages for Object Types — partial support

DDL definitions for User-Defined Types are translated to native Snowflake CREATE TYPE … AS OBJECT / … AS ARRAY where the shape is supported. Constructor calls (for example address_type('123 Main St', …) for object types and VARRAY_TYPE('a', 'b', 'c') for VARRAY / nested-table types) are now also translated to OBJECT_CONSTRUCT(…) :: <type> and ARRAY_CONSTRUCT(…) :: <type> respectively, in INSERT … VALUES, INSERT … SELECT, UPDATE … SET, top-level SELECT, and PL/SQL variable initialization. DML that relies on object-type member functions or other Oracle-specific UDT operations may still require manual review; an SSC-EWI-0073 is emitted in those cases.

2. Create Type creation options are not supported

Actuellement, il n’existe pas de solution connue pour l’une ou l’autre des options de création, c’est pourquoi elles ne sont pas prises en compte lors de la définition du type.

Définition du type de tableau

This is a translation reference to convert the Array Variant of the Oracle Create Type Statements (UDTs) to Snowflake

Note

Oracle VARRAY types are translated to Snowflake CREATE TYPE … AS ARRAY ( element_type ). Fixed varray capacity is not preserved; see SSC-FDM-0043. Column usages may still be migrated to VARIANT in older or mixed scenarios—verify generated DDL for your workload.

VARRAY and nested-table constructor calls (for example phone_list_typ_demo('2000-0000', '4000-0000')) used in INSERT, UPDATE and top-level SELECT are translated to ARRAY_CONSTRUCT(...) :: <type_name>. See VARRAY constructor calls in DML below.

Note

Certaines parties du code de sortie sont omises pour des raisons de clarté.

Description

Les types de tableau définissent une structure de tableau d’un type de données existant (y compris d’autres types personnalisés).

For many workloads, the type definition is emitted as a Snowflake native ARRAY type. Usages in tables and PL/SQL may still involve Semi-structured Data Types or OBJECT depending on context.

CREATE TYPE <type name>
AS { VARRAY | [VARYING] ARRAY } ( <size limit> ) OF <data type>

Modèles d’échantillons de sources

Insertions pour l’utilisation du tableau

VARRAY and nested-table constructor calls used in INSERT … VALUES, INSERT … SELECT, UPDATE and top-level SELECT are translated to ARRAY_CONSTRUCT(...) and explicitly cast to the original UDT name with :: <type>, so column type checks against the UDT continue to succeed.

Oracle
INSERT INTO customer_table_demo(customer_table_id, customer_data) VALUES
(1, phone_list_typ_demo('2000-0000', '4000-0000', '0000-0000'));

INSERT INTO customer_table_demo(customer_table_id, customer_data) VALUES
(1, phone_list_typ_demo('8000-2000', '0000-0000', '5000-0000'));
Snowflake
INSERT INTO customer_table_demo(customer_table_id, customer_data) VALUES
(1, ARRAY_CONSTRUCT('2000-0000', '4000-0000', '0000-0000') :: phone_list_typ_demo);

INSERT INTO customer_table_demo(customer_table_id, customer_data) VALUES
(1, ARRAY_CONSTRUCT('8000-2000', '0000-0000', '5000-0000') :: phone_list_typ_demo);

VARRAY constructor calls in DML

The translator handles standalone constructor calls in INSERT … VALUES, INSERT … SELECT, UPDATE … SET, and top-level SELECT statements. For nested-table types defined with CREATE TYPE … AS TABLE OF … the same ARRAY_CONSTRUCT(...) :: <type> shape is produced.

Oracle
CREATE TYPE VARRAY_TYPE AS VARRAY(3) OF VARCHAR2(50);
/

CREATE TABLE my_varray_table (id NUMBER, varray_column VARRAY_TYPE);
/

INSERT INTO my_varray_table SELECT 1, VARRAY_TYPE('Apple', 'Banana', 'Orange') FROM dual;

CREATE TYPE NUMBER_LIST AS TABLE OF NUMBER;
/

INSERT INTO my_table SELECT 1, NUMBER_LIST(10, 20, 30) FROM dual;
Snowflake
--** SSC-FDM-0043 - ARRAY SIZE LIMIT '3' WAS REMOVED. SNOWFLAKE ARRAYS ARE DYNAMICALLY SIZED. **
CREATE TYPE VARRAY_TYPE AS ARRAY ( VARCHAR(50) );

CREATE OR REPLACE TABLE my_varray_table (
  id NUMBER(38, 18) /*** SSC-FDM-0006 - NUMBER TYPE COLUMN MAY NOT BEHAVE SIMILARLY IN SNOWFLAKE. ***/,
  varray_column ARRAY
)
;

INSERT INTO my_varray_table
SELECT
  1,
  ARRAY_CONSTRUCT('Apple', 'Banana', 'Orange') :: VARRAY_TYPE
FROM
  dual;

CREATE TYPE NUMBER_LIST AS ARRAY ( NUMBER(38, 18) );

INSERT INTO my_table
SELECT
  1,
  ARRAY_CONSTRUCT(10, 20, 30) :: NUMBER_LIST
FROM
  dual;
Oracle (top-level SELECT)
CREATE TYPE STRING_ARRAY AS VARRAY(5) OF VARCHAR2(100);
/

SELECT STRING_ARRAY('hello', 'world') FROM dual;
Snowflake
--** SSC-FDM-0043 - ARRAY SIZE LIMIT '5' WAS REMOVED. SNOWFLAKE ARRAYS ARE DYNAMICALLY SIZED. **
CREATE TYPE STRING_ARRAY AS ARRAY ( VARCHAR(100) );

SELECT
  ARRAY_CONSTRUCT('hello', 'world') :: STRING_ARRAY
FROM
  dual;

Utilisation du type de tableau

Oracle
CREATE TYPE phone_list_typ_demo AS VARRAY(3) OF VARCHAR2(25);
/

CREATE TABLE customer_table_demo (
    customer_table_id INTEGER,
    customer_data phone_list_typ_demo
);
/

SELECT * FROM customer_table_demo;
/
Résultats

CUSTOMER_TABLE_ID

CUSTOMER_DATA

1

[[“2000-0000”,”4000-0000”,”0000-0000”]]

1

[[“8000-2000”,”0000-0000”,”5000-0000”]]

Snowflake
--** SSC-FDM-0043 - ARRAY SIZE LIMIT '3' WAS REMOVED. SNOWFLAKE ARRAYS ARE DYNAMICALLY SIZED. **
CREATE TYPE phone_list_typ_demo AS ARRAY ( VARCHAR(25) );

CREATE OR REPLACE TABLE customer_table_demo (
        customer_table_id INTEGER,
        customer_data phone_list_typ_demo
    )
COMMENT = '{"origin":"sf_sc","name":"snowconvert","version":{"major":1, "minor":0},"attributes":{"component":"oracle"}}'
;

CREATE OR REPLACE VIEW PUBLIC.customer_table_demo_view
COMMENT = '{ "origin": "sf_sc", "name": "snowconvert", "version": {  "major": 0,  "minor": 0,  "patch": "0" }, "attributes": {  "component": "oracle",  "convertedOn": "" }}'
AS
SELECT
        customer_table_id,
        customer_data
FROM
        customer_table_demo;

    SELECT * FROM
        customer_table_demo_view;
Résultats

CUSTOMER_TABLE_ID

CUSTOMER_DATA

1

[[“2000-0000”, “4000-0000”, “0000-0000”]]

1

[[“8000-2000”, “0000-0000”, “5000-0000”]]

Problèmes connus

1. Create Type creation options are not supported

Actuellement, il n’existe pas de solution connue pour l’une ou l’autre des options de création, c’est pourquoi elles ne sont pas prises en compte lors de la définition du type.

2. Migrated code output is not functional

Les instructions sont modifiées inutilement, ce qui fait qu’elles ne sont plus fonctionnelles dans le code de sortie. Cette question sera abordée lorsqu’une transformation adéquate sera mise en place.

EWIs connexes

  1. SSC-EWI-0062: L’utilisation du type personnalisé a changé en variante.

  2. SSC-EWI-0073 : En attente de l’examen de l’équivalence fonctionnelle.

Définitions des fonctions membres

This is a translation reference to convert the Member Functions of the Oracle Create Type Statements (UDTs) to Snowflake

Danger

SnowConvert AI ne reconnaît toujours pas les fonctions membres ni les définitions de corps de type. Cette page n’est utilisée que comme référence future pour la traduction.

Note

Certaines parties du code de sortie sont omises pour des raisons de clarté.

Description

Comme les autres définitions de classe, Oracle TYPE peut mettre en œuvre des méthodes pour exposer des comportements basés sur ses attributs. MEMBER FUCTION sera transformée en procédures stockées de Snowflake, afin de maintenir l’équivalence fonctionnelle en raison des limites.

Étant donné que les fonctions sont transformées en procédures, la référence de transformation pour PL/SQL s’applique également ici.

Modèles d’échantillons de sources

Insertions pour la fonction membre Simple square()

Les données suivantes seront insérées dans la table avant la requête de sélection. Notez que ces insertions doivent actuellement être migrées manuellement dans 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);

Fonction simple square()

Oracle
-- 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;
/

-- TABLE
CREATE TABLE table_member_function_demo (column1 type_member_function_demo);
/

-- QUERYING DATA
SELECT
    t.column1.get_square()
FROM
    table_member_function_demo t;
/
Résultats

COLUMN1TGET_SQUARE

25

Snowflake
-- TYPE DECLARATION
!!!RESOLVE EWI!!! /*** SSC-EWI-0056 - CUSTOM TYPES ARE NOT SUPPORTED IN SNOWFLAKE BUT REFERENCES TO THIS CUSTOM TYPE WERE CHANGED TO VARIANT ***/!!!
CREATE TYPE type_member_function_demo AS OBJECT (
    a1 NUMBER,
    MEMBER FUNCTION get_square RETURN NUMBER
)
;

---- TYPE BODY DECLARATION
--!!!RESOLVE EWI!!! /*** SSC-EWI-OR0007 - CREATE TYPE WITHOUT BODY IS NOT SUPPORTED IN SNOWFLAKE ***/!!!
--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
   ;

-- TABLE
CREATE OR REPLACE TABLE table_member_function_demo (column1 VARIANT !!!RESOLVE EWI!!! /*** SSC-EWI-0062 - CUSTOM TYPE 'type_member_function_demo' USAGE CHANGED TO VARIANT ***/!!!
)
COMMENT = '{"origin":"sf_sc","name":"snowconvert","version":{"major":1, "minor":0},"attributes":{"component":"oracle"}}'
;

CREATE OR REPLACE VIEW PUBLIC.table_member_function_demo_view
<strong>COMMENT = '{ "origin": "sf_sc", "name": "snowconvert", "version": {  "major": 0,  "minor": 0,  "patch": "0" }, "attributes": {  "component": "oracle",  "convertedOn": "" }}'
</strong><strong>AS
</strong>SELECT
    column1:a1 :: NUMBER AS a1
FROM
    table_member_function_demo;

-- QUERYING DATA
SELECT
    t.column1.get_square() !!!RESOLVE EWI!!! /*** SSC-EWI-0073 - PENDING FUNCTIONAL EQUIVALENCE REVIEW FOR 't.column1.get_square' NODE ***/!!!
FROM
    table_member_function_demo t;
Résultats

GET_SQUARE

25

Problèmes connus

Aucun problème connu.

EWIs connexes

  1. SSC-EWI-0056 : Create table n’est pas pris en charge.

  2. SSC-EWI-0062: L’utilisation du type personnalisé a changé en variante.

  3. SSC-EWI-0073 : En attente de l’examen de l’équivalence fonctionnelle.

  4. SSC-EWI-OR0007: Create Type n’est pas pris en charge dans Snowflake

Définition du type de table imbriquée

This is a translation reference to convert the Nested Table Variant of the Oracle Create Type Statements (UDTs) to Snowflake

Note

Standalone CREATE TYPE … AS TABLE OF element_type is translated to Snowflake CREATE TYPE … AS ARRAY ( element_type ) when the element type is supported. Nested tables used as table columns may still require manual review depending on DML and PL/SQL usage.

Description

Nested Table Types define an embedded table structure of a previously existing datatype (including other Custom Types). They are closely related to Array Type definitions; SnowConvert maps many patterns to Snowflake ARRAY.

CREATE TYPE <type name> AS TABLE OF <data type>

Modèles d’échantillons de sources

Utilisation du type de table imbriquée

Oracle
CREATE TYPE textdoc_typ AS OBJECT (
    document_typ VARCHAR2(32),
    formatted_doc BLOB
);
/

CREATE TYPE textdoc_tab AS TABLE OF textdoc_typ;
/
Snowflake
CREATE TYPE textdoc_typ AS OBJECT (
    document_typ VARCHAR(32),
    formatted_doc BINARY
)
;

CREATE TYPE textdoc_tab AS ARRAY ( textdoc_typ );

Problèmes connus

1. Create Type creation options are not supported

Actuellement, il n’existe pas de solution connue pour les options de création ; c’est pourquoi elles ne sont pas prises en compte lors de la définition du type.

EWIs connexes

  1. SSC-EWI-0073 : En attente de l’examen de l’équivalence fonctionnelle

  2. SSC-EWI-0056 : Create table n’est pas pris en charge.

Définition du type d’objet

This is a translation reference to convert the Object Variant of the Oracle Create Type Statements (UDTs) to Snowflake

Note

SnowConvert AI prend en charge une traduction pour les définitions de type d’objet elles-mêmes. Cependant, leur utilisation est n’est pas encore prête.

Note

Certaines parties du code de sortie sont omises pour des raisons de clarté.

Description

Les types d’objets définissent une structure de données similaire à un enregistrement, avec les avantages supplémentaires des définitions des fonctions membres. Cela signifie que leurs données peuvent être utilisées dans le cadre d’un comportement au sein du type.

For the translation of object types, the type definition is mapped to Snowflake’s native CREATE TYPE … AS OBJECT (…) where the attribute list is supported, and constructor calls to the type are translated to OBJECT_CONSTRUCT(<field>, <value>, …) :: <type_name>. SnowConvert AI uses the symbol table to recover the field names from the original CREATE TYPE, so positional constructor arguments are mapped to the correct field names in upper-case. When the type symbol cannot be resolved (for example, because the CREATE TYPE is not part of the migrated source set), the constructor call is preserved and an SSC-EWI-0073 is emitted for manual review.

For legacy or partially-supported scenarios where the object type cannot be expressed natively, the column in dependent tables may still be migrated to VARIANT and an auxiliary view is added so that downstream SELECTs and views to the original table continue to work.

CREATE TYPE <type name> AS OBJECT
( [{<type column definition> | type method definition } , ...]);

Modèles d’échantillons de sources

Object Type constructor calls

Object-type constructor calls are translated to OBJECT_CONSTRUCT('FIELD1', value1, 'FIELD2', value2, …) :: <type_name>. The cast to the original UDT name is preserved so column type checks and downstream OBJECT_INSERT / member access continue to work without changes. The transformation applies to constructor calls inside variable initialization, INSERT … VALUES, INSERT … SELECT, UPDATE … SET, and top-level SELECT expressions.

Note

Field names in the generated OBJECT_CONSTRUCT keys are always upper-case (for example 'NAME', 'AGE'). Snowflake object key lookups are case-sensitive, so downstream references using lowercase or mixed-case semi-structured path syntax (for example obj:name) will return NULL. Use the exact upper-case key or quote it consistently throughout the migrated code.

Oracle
CREATE OR REPLACE TYPE Person_Type AS OBJECT (
  Name VARCHAR2(50),
  Age NUMBER
);
/

CREATE OR REPLACE PROCEDURE test_udt_constructor
AS
  person Person_Type := Person_Type('Alice', 30);
BEGIN
  NULL;
END;
Snowflake
CREATE TYPE Person_Type AS OBJECT (Name VARCHAR(50), Age NUMBER(38, 18));

CREATE OR REPLACE PROCEDURE test_udt_constructor ()
RETURNS VARCHAR
LANGUAGE SQL
EXECUTE AS CALLER
AS
$$
  DECLARE
    person Person_Type := OBJECT_CONSTRUCT('NAME', 'Alice', 'AGE', 30) :: Person_Type;
  BEGIN
    NULL;
  END;
$$;
Oracle (constructor in INSERT … VALUES and UPDATE … SET)
CREATE OR REPLACE TYPE address_type AS OBJECT (
  street VARCHAR2(100),
  city VARCHAR2(50),
  state VARCHAR2(2),
  postal_code VARCHAR2(10)
);
/

INSERT INTO employees
VALUES (1, 'John', 'Doe', address_type('123 Main St', 'Los Angeles', 'CA', '90001'));

UPDATE employees
SET home_address = address_type('456 Oak Ave', 'New York', 'NY', '10001')
WHERE employee_id = 1;
Snowflake
CREATE TYPE address_type AS OBJECT (street VARCHAR(100), city VARCHAR(50), state VARCHAR(2), postal_code VARCHAR(10));

INSERT INTO employees
VALUES (1, 'John', 'Doe', OBJECT_CONSTRUCT('STREET', '123 Main St', 'CITY', 'Los Angeles', 'STATE', 'CA', 'POSTAL_CODE', '90001') :: address_type);

UPDATE employees
  SET
    home_address = OBJECT_CONSTRUCT('STREET', '456 Oak Ave', 'CITY', 'New York', 'STATE', 'NY', 'POSTAL_CODE', '10001') :: address_type
  WHERE
    employee_id = 1;
Oracle (constructor when the type symbol is not in the migrated source)
CREATE OR REPLACE FUNCTION Get_Person_Func
RETURN Person_Type
AS
    v_person Person_Type;
BEGIN
    v_person := Person_Type('Jane Doe', 25);
    RETURN v_person;
END;
Snowflake
CREATE OR REPLACE FUNCTION Get_Person_Func ()
RETURNS Person_Type
LANGUAGE SQL
AS
$$
  WITH declaration_variables_cte1 AS
  (
    SELECT
      Person_Type('Jane Doe', 25) !!!RESOLVE EWI!!! /*** SSC-EWI-0073 - PENDING FUNCTIONAL EQUIVALENCE REVIEW FOR 'Person_Type' NODE ***/!!! AS
      v_person
  )
  SELECT
    v_person
  FROM
    declaration_variables_cte1
$$;

Insertions pour l’utilisation de types simples

Les données suivantes seront insérées dans la table avant la requête de sélection. Notez que ces insertions doivent actuellement être migrées manuellement dans Snowflake.

Oracle
INSERT INTO customer_table_demo(customer_table_id, customer_data)
VALUES ( 1, customer_typ_demo(1, 'First Name 1', 'Last Name 1'));

INSERT INTO customer_table_demo(customer_table_id, customer_data)
VALUES ( 2, customer_typ_demo(2, 'First Name 2', 'Last Name 2'));
Snowflake
INSERT INTO customer_table_demo(customer_table_id, customer_data)
VALUES ( 1, customer_typ_demo(1, 'First Name 1', 'Last Name 1') !!!RESOLVE EWI!!! /*** SSC-EWI-0073 - PENDING FUNCTIONAL EQUIVALENCE REVIEW FOR 'customer_typ_demo' NODE ***/!!!);

INSERT INTO customer_table_demo(customer_table_id, customer_data)
VALUES ( 2, customer_typ_demo(2, 'First Name 2', 'Last Name 2') !!!RESOLVE EWI!!! /*** SSC-EWI-0073 - PENDING FUNCTIONAL EQUIVALENCE REVIEW FOR 'customer_typ_demo' NODE ***/!!!);

Utilisation du type simple

Oracle
CREATE TYPE customer_typ_demo AS OBJECT (
    customer_id INTEGER,
    cust_first_name VARCHAR2(20),
    cust_last_name VARCHAR2(20)
);

CREATE TABLE customer_table_demo (
    customer_table_id INTEGER,
    customer_data customer_typ_demo
);

SELECT * FROM customer_table_demo;
Résultats

CUSTOMER_TABLE_ID

CUSTOMER_DATA

1

[1, Prénom 1, Nom 1]

2

[2, Prénom 2, Nom 2]

Snowflake
!!!RESOLVE EWI!!! /*** SSC-EWI-0056 - CUSTOM TYPES ARE NOT SUPPORTED IN SNOWFLAKE BUT REFERENCES TO THIS CUSTOM TYPE WERE CHANGED TO VARIANT ***/!!!
CREATE TYPE customer_typ_demo AS OBJECT (
    customer_id INTEGER,
    cust_first_name VARCHAR2(20),
    cust_last_name VARCHAR2(20)
)
;

CREATE OR REPLACE TABLE customer_table_demo (
        customer_table_id INTEGER,
        customer_data VARIANT !!!RESOLVE EWI!!! /*** SSC-EWI-0062 - CUSTOM TYPE 'customer_typ_demo' USAGE CHANGED TO VARIANT ***/!!!
    )
COMMENT = '{"origin":"sf_sc","name":"snowconvert","version":{"major":1, "minor":0},{"attributes":{"component":"oracle"}}}'
;

CREATE OR REPLACE VIEW PUBLIC.customer_table_demo_view
COMMENT = '{ "origin": "sf_sc", "name": "snowconvert", "version": {  "major": 0,  "minor": 0,  "patch": "0" }, "attributes": {  "component": "oracle",  "convertedOn": "" }}'
AS
SELECT
        customer_table_id,
        customer_data:customer_id :: INTEGER AS customer_id,
        customer_data:cust_first_name :: VARCHAR AS cust_first_name,
        customer_data:cust_last_name :: VARCHAR AS cust_last_name
FROM
        customer_table_demo;

    SELECT * FROM
        customer_table_demo_view;
Résultats

CUSTOMER_TABLE_ID

CUST_ID

CUST_FIRST_NAME

CUST_LAST_NAME

1

1

Prénom 1

Nom 1

2

2

Prénom 2

Nom 2

Insertions pour l’utilisation de types imbriqués

Ces instructions doivent être placées entre la création de la table et l’instruction select pour tester la sortie.

Oracle
INSERT INTO customer_table_demo(customer_id, customer_data) values
(1, customer_typ_demo('Customer 1', email_typ_demo('email@domain.com')));

INSERT INTO customer_table_demo(customer_id, customer_data) values
(2, customer_typ_demo('Customer 2', email_typ_demo('email2@domain.com')));
Snowflake
INSERT INTO customer_table_demo(customer_id, customer_data) values
(1, customer_typ_demo('Customer 1', email_typ_demo('email@domain.com') !!!RESOLVE EWI!!! /*** SSC-EWI-0073 - PENDING FUNCTIONAL EQUIVALENCE REVIEW FOR 'email_typ_demo' NODE ***/!!!) !!!RESOLVE EWI!!! /*** SSC-EWI-0073 - PENDING FUNCTIONAL EQUIVALENCE REVIEW FOR 'customer_typ_demo' NODE ***/!!!);

INSERT INTO customer_table_demo(customer_id, customer_data) values
(2, customer_typ_demo('Customer 2', email_typ_demo('email2@domain.com') !!!RESOLVE EWI!!! /*** SSC-EWI-0073 - PENDING FUNCTIONAL EQUIVALENCE REVIEW FOR 'email_typ_demo' NODE ***/!!!) !!!RESOLVE EWI!!! /*** SSC-EWI-0073 - PENDING FUNCTIONAL EQUIVALENCE REVIEW FOR 'customer_typ_demo' NODE ***/!!!);

Utilisation des types imbriqués

Oracle
CREATE TYPE email_typ_demo AS OBJECT (email VARCHAR2(20));

CREATE TYPE customer_typ_demo AS OBJECT (
    cust_name VARCHAR2(20),
    cust_email email_typ_demo
);

CREATE TABLE customer_table_demo (
    customer_id INTEGER,
    customer_data customer_typ_demo
);

SELECT * FROM customer_table_demo;
Résultats

CUSTOMER_ID

CUSTOMER_DATA

1

[client 1, [email@domain.com]]

2

[client 2, [email2@domain.com]]

Snowflake
!!!RESOLVE EWI!!! /*** SSC-EWI-0056 - CUSTOM TYPES ARE NOT SUPPORTED IN SNOWFLAKE BUT REFERENCES TO THIS CUSTOM TYPE WERE CHANGED TO VARIANT ***/!!!
CREATE TYPE email_typ_demo AS OBJECT (email VARCHAR2(20))
;

!!!RESOLVE EWI!!! /*** SSC-EWI-0056 - CUSTOM TYPES ARE NOT SUPPORTED IN SNOWFLAKE BUT REFERENCES TO THIS CUSTOM TYPE WERE CHANGED TO VARIANT ***/!!!

CREATE TYPE customer_typ_demo AS OBJECT (
    cust_name VARCHAR2(20),
    cust_email email_typ_demo
)
;

CREATE OR REPLACE TABLE customer_table_demo (
    customer_id INTEGER,
    customer_data VARIANT !!!RESOLVE EWI!!! /*** SSC-EWI-0062 - CUSTOM TYPE 'customer_typ_demo' USAGE CHANGED TO VARIANT ***/!!!
)
COMMENT = '{"origin":"sf_sc","name":"snowconvert","version":{"major":1, "minor":0},{"attributes":{"component":"oracle"}}}'
;

CREATE OR REPLACE VIEW PUBLIC.customer_table_demo_view
COMMENT = '{ "origin": "sf_sc", "name": "snowconvert", "version": {  "major": 0,  "minor": 0,  "patch": "0" }, "attributes": {  "component": "oracle",  "convertedOn": "" }}'
AS
SELECT
    customer_id,
    customer_data:cust_name :: VARCHAR AS cust_name,
    customer_data:cust_email:email :: VARCHAR AS email
FROM
    customer_table_demo;

SELECT * FROM
    customer_table_demo_view;
Résultats

CUSTOMER_ID

CUST_NAME

CUST_EMAIL

1

Client 1

email@domain.com

2

Client 2

e-mail2@domain.com

Problèmes connus

1. Migrated code output is not the same

L’instruction view est modifiée inutilement, ce qui fait que la table n’a plus le même comportement dans le code de sortie. Un élément de travail a été mis en place pour corriger ce problème.

2. DML for User-defined Types — partial support

Constructor calls to object types (for example address_type('123 Main St', …)) and to collection types (VARRAY and nested-table) are now translated automatically when they appear in INSERT … VALUES, INSERT … SELECT, UPDATE … SET, and top-level SELECT expressions, as well as in PL/SQL variable initialization. See Object Type constructor calls above. Other DML shapes that depend on object-type member functions or implicit type promotion may still require manual review.

3. Create Type creation options are not supported

Actuellement, il n’existe pas de solution connue pour l’une ou l’autre des options de création, c’est pourquoi elles ne sont pas prises en compte lors de la définition du type.

EWIs connexes

  1. SSC-EWI-0056 : Create table n’est pas pris en charge.

  2. SSC-EWI-0062: L’utilisation du type personnalisé a changé en variante.

  3. SSC-EWI-0073 : En attente de l’examen de l’équivalence fonctionnelle.

Définition du sous-type

This is a translation reference to convert the Subtype Variant of the Oracle Create Type Statements (UDTs) to Snowflake

Danger

Comme il n’y a aucune solution de contournement connue, SnowConvert AI ne reconnaît que ces définitions et ne prend en charge aucune traduction pour celles-ci.

Description

Les sous-types définissent une structure de données similaire à un enregistrement, avec les avantages supplémentaires des définitions des fonctions membres. Cela signifie que leurs données peuvent être utilisées dans le cadre d’un comportement au sein du type. Contrairement aux types d’objets, les sous-types sont construits comme une extension d’un autre type existant.

En ce qui concerne les définitions de sous-types, il n’y a toujours pas de traduction, mais il pourrait y avoir un moyen de les réimplémenter en utilisant les définitions des types d’objets et en utilisant ensuite leur traduction respective.

CREATE TYPE <type name> UNDER <super type name>
( [{<type column definition> | type method definition } , ...]);

Modèles d’échantillons de sources

Sous-types d’un type d’objet

Oracle
CREATE TYPE person_t AS OBJECT (name VARCHAR2(100), ssn INTEGER) 
   NOT FINAL;
/

CREATE TYPE employee_t UNDER person_t 
   (department_id INTEGER, salary INTEGER) 
   NOT FINAL;
/

CREATE TYPE part_time_emp_t UNDER employee_t (num_hrs INTEGER);
/
Snowflake
!!!RESOLVE EWI!!! /*** SSC-EWI-0056 - CUSTOM TYPES ARE NOT SUPPORTED IN SNOWFLAKE BUT REFERENCES TO THIS CUSTOM TYPE WERE CHANGED TO VARIANT ***/!!!
CREATE TYPE person_t AS OBJECT (name VARCHAR2(100), ssn INTEGER)
   NOT FINAL;

--!!!RESOLVE EWI!!! /*** SSC-EWI-OR0007 - CREATE TYPE SUBTYPE IS NOT SUPPORTED IN SNOWFLAKE ***/!!!

--CREATE TYPE employee_t UNDER person_t
--   (department_id INTEGER, salary INTEGER)
--   NOT FINAL
            ;

--!!!RESOLVE EWI!!! /*** SSC-EWI-OR0007 - CREATE TYPE SUBTYPE IS NOT SUPPORTED IN SNOWFLAKE ***/!!!

--CREATE TYPE part_time_emp_t UNDER employee_t (num_hrs INTEGER)
                                                              ;

Problèmes connus

1. Create Type creation options are not supported

Actuellement, il n’existe pas de solution connue pour l’une ou l’autre des options de création, c’est pourquoi elles ne sont pas prises en compte lors de la définition du type.

EWIs connexes

  1. SSC-EWI-0056 : Create table n’est pas pris en charge.

  2. SSC-EWI-OR0007 : Type de création non pris en charge dans Snowflake.