SnowConvert AI - Oracle - Built-In packages¶
Translation reference for Built-in packages.
Description¶
Oracle supplies many PL/SQL packages with the Oracle server to extend database functionality and provide PL/SQL access to SQL features. (Oracle PL/SQL Built-in Packages (https://docs.oracle.com/en/database/oracle/oracle-database/21/arpls/introduction-to-oracle-supplied-plsql-packages-and-types.html#GUID-4AA6AA30-CAEE-4DCD-B214-9AD51D0229B4))
DBMS_OUTPUT¶
Description¶
The
DBMS_OUTPUTpackage is especially useful for displaying PL/SQL debugging information. (Oracle PL/SQL DBMS_OUTPUT (https://docs.oracle.com/en/database/oracle/oracle-database/21/arpls/DBMS_OUTPUT.html#GUID-C1400094-18D5-4F36-A2C9-D28B0E12FD8C))
PUT_LINE procedure¶
Translation reference for DBMS_OUTPUT.PUT_LINE.
Description¶
This procedure places a line in the buffer. (Oracle PL/SQL DBMSOUTPUT.PUT_LINE (https://docs.oracle.com/en/database/oracle/oracle-database/21/arpls/DBMS_OUTPUT.html#GUID-19FA480D-591E-4584-9650-5D37C4AFA530))
This UDF is implemented using a temporary table to insert the data to be displayed to replicate the functionality of Oracle DBMS_OUTPUT.PUT_LINE function.
Syntax¶
Custom procedure¶
Setup data¶
The DBMS_OUTPUT schema must be created.
DBMS_OUTPUT.PUT_LINE(VARCHAR)¶
Parameters¶
LOG: Item in a buffer that you want to display.
Note
Note that this is using a temporary table, if you want the data to persist after a session ends, please remove TEMPORARY from the CREATE TABLE.
The temporary tables store non-permanent transitory data. They only exist within the session in which they were created and persist only for the rest of the session. After the session ends, the data stored in the table is completely removed from the system and is therefore not recoverable, either by the user who created the table or by Snowflake.
Warning
If you do not use the temporary table, keep in mind that you may need another column in the table where the USER running DBMS_OUTPUT.PUT_LINE UDF is inserted to avoid confusion.
Usage example¶
Oracle¶
Result¶
Snowflake¶
Result¶
Known Issues¶
The UDF code will remain commented out because it can affect performance, if the user decides to use it, they just need to uncomment the code.
The user can modify the UDF so that the necessary information is inserted into the DBMS_OUTPUT.PUT_LINE table.
DBMS_LOB¶
Description¶
The
DBMS_LOBpackage provides subprograms to operate onBLOBs,CLOBs,NCLOBs,BFILEs, and temporaryLOBs. You can useDBMS_LOBto access and manipulate specific parts of a LOB or complete LOBs. (Oracle PL/SQL DBMS_LOB (https://docs.oracle.com/en/database/oracle/oracle-database/21/arpls/DBMS_LOB.html#GUID-A35DE03B-41A6-4E55-8CDE-77737FED9306))
SUBSTR Function¶
Translation reference for DBMS_LOB.SUBSTR.
Description¶
This function returns
amountbytes or characters of a LOB, starting from an absoluteoffsetfrom the beginning of the LOB. (Oracle PL/SQL DBMS_LOB.SUBSTR (https://docs.oracle.com/en/database/oracle/oracle-database/21/arpls/DBMS_LOB.html))
This built-in function is replaced with Snowflake SUBSTR function. However, there are some differences.
Note
The amount and offset parameters are inverted in Snowflake
Syntax¶
Function overloads¶
DBMS_LOB.SUBSTR(‘string’, amount, offset)
Usage example¶
Oracle¶
Result¶
Snowflake¶
Result¶
DBMS_LOB.SUBSTR(BLOB, amount, offset)¶
Usage example¶
Warning
Result values in Oracle and Snowflake are being converted from bytes to strings for easier understanding of the function.
For Snowflake consider using:
hex_decode_string( to_varchar(SUBSTR(blob_column, 1, 6), ‘HEX’));
and for Oracle consider using:
utl_raw.cast_to_varchar2(DBMS_LOB.SUBSTR(blob_column, 1, 6));
to obtain the result as a string.
Oracle¶
Result¶
Snowflake¶
Result¶
Warning
Note: UTL_RAW.CAST_TO_RAW() is currently not being transformed to TO_BINARY(). The function is used to show the functional equivalence of the example.
DBMS_LOB.SUBSTR(CLOB, amount, offset)¶
Usage example¶
Oracle¶
Result¶
Snowflake¶
Result¶
Warning
Note: UTL_RAW.CAST_TO_RAW() is currently not being transformed to TO_BINARY(). The function is used to show the functional equivalence of the example.
DBMS_LOB.SUBSTR(BFILE, amount, offset)¶
Usage example¶
Using DBMS_LOB.SUBSTR() on a BFILE column returns a substring of the file content.
Warning
Next example is not a current migration, but a functional example to show the differences of the SUBSTR function on BFILE types.
File Content (file.txt):
Oracle¶
Console Log¶
Snowflake¶
BFILE columns are translated into VARCHAR columns, therefore applying a SUBSTR function on the same column would return a substring of the file name, not the file content.
Result¶
SUBSTR(bfile_column, 1, 9) |
|---|
MY_DIR\fi |
Known Issues¶
1. Using DBMS_LOB.SUBSTR with BFILE columns¶
The current transformation for BFILE datatypes in columns is VARCHAR, where the name of the file is stored as a string. Therefore applying the SUBSTR function on a BFILE column after transformation will return a substring of the file name, while Oracle would return a substring of the file content.
Related EWIs¶
SSC-EWI-OR0076: Built In Package Not Supported.
SSC-FDM-OR0035: DBMS_OUTPUT.PUTLINE check UDF implementation.
UTL_FILE¶
Description¶
With
UTL_FILEpackage, PL/SQL programs can read and write text files. (Oracle PL/SQL UTL_FILE (https://docs.oracle.com/en/database/oracle/oracle-database/21/arpls/UTL_FILE.html#GUID-EBC42A36-EB72-4AA1-B75F-8CF4BC6E29B4))
FCLOSE procedure¶
Translation reference for UTL_FILE.FCLOSE.
Description¶
This procedure closes an open file identified by a file handle. (Oracle PL/SQL UTL_FILE.FCLOSE (https://docs.oracle.com/en/database/oracle/oracle-database/21/arpls/UTL_FILE.html#GUID-68874564-1A2C-4071-8D48-60539C805E0D))
This procedure is implemented using Snowflake STAGE to store the written text files.
Syntax¶
Setup data¶
The
UTL_FILEschema must be created.
If you want to download the file, run the following command.
Warning
The GET command runs in Snowflake CLI.
Custom procedure overloads¶
UTL_FILE.FCLOSE(VARCHAR)¶
Parameters¶
FILE: Active file handler returned from the call to
UTL_FILE.FOPEN
Functionality¶
This procedure uses the FOPEN_TABLES_LINES table created in the UTL_FILE.FOPEN procedure.
This procedure writes to the utlfile_local_directory stage all lines with the same FHANDLE from the file in FOPEN_TABLES_LINES.
Note
Note that this procedure uses the stage that was created previously. For now, if you want to write the file in another stage, you must modify the name.
These procedures are implemented for the internal stages in the
COPY INTO
Usage example¶
Oracle¶
Warning
To run this example, see ORACLE UTL_FILE (https://docs.oracle.com/en/database/oracle/oracle-database/21/arpls/UTL_FILE.html#GUID-FA16A38B-26AA-4002-9BE0-7D3950557F8C)
Snowflake¶
Known Issues¶
1. Modify the procedure for changing the name of the stage.¶
The user can modify the procedure if it is necessary to change the name of the stage.
2. Location static.¶
The location used to write to this procedure is static. A new version of the procedure is expected to increase its extensibility by using the location that has the FILE parameter.
5. Files supported.¶
This procedure for now, only writes .CSV files.
Related EWIs¶
SSC-FDM-0015: Data Type Not Recognized.
SSC-FDM-OR0036: Unnecessary built-in packages parameters.
FOPEN procedure¶
Translation reference for UTL_FILE.FOPEN.
Description¶
This procedure opens a file. (Oracle PL/SQL UTL_FILE.FOPEN (https://docs.oracle.com/en/database/oracle/oracle-database/21/arpls/UTL_FILE.html#GUID-DF14ADC3-983D-4E0F-BE2C-60733FF58539))
This procedure is implemented using Snowflake STAGE to store the text files.
The user is in charge of uploading the local files to the STAGE to be used by the procedure.
Syntax¶
Setup data¶
The
UTL_FILEschema must be created.
Create the stage
utlfile_local_directory.
If the value in the
OPEN_MODEparameter is w or r it is necessary to upload the file in theutlfile_local_directory.
Warning
The PUT command runs in Snowflake CLI.
Custom procedure overloads¶
UTL_FILE.FOPEN( VARCHAR, VARCHAR)¶
Parameters¶
FILENAME: The name of the file, including extension**.**
OPEN_MODE: Specifies how the file is opened.
Open modes¶
The Oracle Built-in package UTL_FILE.FOPEN (https://docs.oracle.com/en/database/oracle/oracle-database/21/arpls/UTL_FILE.html#GUID-DF14ADC3-983D-4E0F-BE2C-60733FF58539) procedure supports six modes of how to open the file, but only three of them are supported in the Snowscripting procedure.
OPEN_MODE |
DESCRIPTION |
STATUS |
|---|---|---|
w |
Write mode |
Supported |
a |
Append mode |
Supported |
r |
Read mode |
Supported |
rb |
Read byte mode |
Unsupported |
wb |
Write byte mode |
Unsupported |
ab |
Append byte mode |
Unsupported |
Functionality¶
This procedure uses two tables with which the operation of opening a file will be emulated. The FOPEN_TABLES table will store the files that are open and the FOPEN_TABLES_LINES table stores the lines that each file owns.
If the file is opened in write mode, a new file is created, if it is opened in read or append mode, it loads the lines of the file in FOPEN_TABLES_LINES and inserts the file in FOPEN_TABLES.
Note
Note that this procedure uses the stage that was created previously. For now, if you want to use another name for the stage, you must modify the procedure.
These procedures are implemented for the internal stages in the
COPY INTO
Usage example¶
Oracle¶
Warning
To run this example, see ORACLE UTL_FILE (https://docs.oracle.com/en/database/oracle/oracle-database/21/arpls/UTL_FILE.html#GUID-FA16A38B-26AA-4002-9BE0-7D3950557F8C)
Snowflake¶
Known Issues¶
1. Modify the procedure for changing the name of the stage.¶
The user can modify the procedure if it is necessary to change the name of the stage.
2. LOCATION parameter is not used.¶
The LOCATION parameter is not used now because the stage used in the procedure is static. It is planned for an updated version of the procedure to increase its extensibility by using this parameter to enter the name of the stage where the file you want to open is located.
3. MAX_LINESIZE parameter is not used.¶
The Oracle Built-in package UTL_FILE.FOPEN (https://docs.oracle.com/en/database/oracle/oracle-database/21/arpls/UTL_FILE.html#GUID-DF14ADC3-983D-4E0F-BE2C-60733FF58539) procedure has the MAX_LINESIZE parameter, but in the Snowscripting procedure it is removed because it is not used.
4. OPEN_MODE values supported.¶
This procedure supports write (w), read (r), and append (a) modes to open files.
5. Files supported.¶
This procedure for now, only supports .CSV files.
Related EWIs¶
SSC-FDM-0015: Data Type Not Recognized.
SSC-FDM-OR0036: UnnecessaryBuiltInPackagesParameters
PUT_LINE procedure¶
Translation reference for UTL_FILE.PUT_LINE.
Description¶
This procedure writes the text string stored in the buffer parameter to the open file identified by the file handle. (Oracle PL/SQL UTL_FILE.PUT_LINE (https://docs.oracle.com/en/database/oracle/oracle-database/21/arpls/UTL_FILE.html#GUID-BC046363-6F14-4128-B4D2-836DDBDB9B48))
Syntax¶
Setup data¶
The
UTL_FILEschema must be created.
Custom UDF¶
UTL_FILE.PUT_LINE(VARCHAR, VARCHAR)¶
Parameters¶
FILE: Active file handler returned from the call to
UTL_FILE.FOPENBUFFER: Text buffer that contains the text to be written to the file**.**
Functionality¶
This procedure uses the FOPEN_TABLES_LINES table created in the UTL_FILE.FOPEN procedure.
If the OPEN_MODE of the file is write (w) or append (a), it inserts the buffer into FOPEN_TABLES_LINES, but if the OPEN_MODE is read (r), it throws the File_is_read_only exception.
Usage example¶
Oracle¶
Warning
To run this example, see ORACLE UTL_FILE (https://docs.oracle.com/en/database/oracle/oracle-database/21/arpls/UTL_FILE.html#GUID-FA16A38B-26AA-4002-9BE0-7D3950557F8C)
Snowflake¶
Known Issues¶
1. AUTOFLUSH parameter is not used.¶
The Oracle Built-in package UTL_FILE.PUT_LINE (https://docs.oracle.com/en/database/oracle/oracle-database/21/arpls/UTL_FILE.html#GUID-BC046363-6F14-4128-B4D2-836DDBDB9B48) procedure has the AUTOFLUSH parameter, but in the Snowscripting procedure it is removed because it is not used.
Related EWIs¶
SSC-FDM-0015: Data Type Not Recognized.
SSC-FDM-OR0036: Unnecessary built-in packages parameters.
DBMS_RANDOM¶
Description¶
The
DBMS_RANDOMpackage provides a built-in random number generator.DBMS_RANDOMis not intended for cryptography. (Oracle PL/SQL DBMS_RANDOM (https://docs.oracle.com/en/database/oracle/oracle-database/21/arpls/DBMS_RANDOM.html#GUID-8DC48B0C-3707-4172-A306-C0308DD2EB0F))
VALUE functions¶
Translation reference for DBMS_RANDOM.VALUE.
Description¶
The basic function gets a random number, greater than or equal to 0 and less than 1. Alternatively, you can get a random Oracle number
X, whereXis greater than or equal tolowand less thanhigh. (Oracle PL/SQL DBMS_RANDOM.VALUE (https://docs.oracle.com/en/database/oracle/oracle-database/21/arpls/DBMS_RANDOM.html#GUID-AAD9E936-D74F-440D-9E16-24F3F0DE8D31))
This UDF is implemented using the Math.random (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random) function of Javascript to replicate the functionality of Oracle DBMS_RANDOM.VALUE function.
Syntax¶
Custom UDF overloads¶
Setup data¶
The DBMS_RANDOM schema must be created.
DBMS_RANDOM.VALUE()¶
Parameters¶
No parameters.
Note
Note: The UDF only supports approximately between 9 and 10 digits in the decimal part of the number (9 or 10 digits of precision)
Usage example¶
Oracle¶
Result¶
Note
The function can be called either_DBMS_RANDOM.VALUE()_ or DBMS_RANDOM.VALUE.
Snowflake¶
Result¶
Note
In Snowflake, you must put the parentheses.
DBMS_RANDOM.VALUE(NUMBER, NUMBER)
Parameters¶
low: The lowest
NUMBERfrom which a random number is generated. The number generated is greater than or equal tolow.high: The highest
NUMBERused as a limit when generating a random number. The number generated will be less thanhigh.
Note
The Oracle DBMS_RANDOM.VALUE(low, high) function does not require parameters to have a specific order so the Snowflake UDF is implemented to support this feature by always taking out the highest and lowest number.
The UDF only supports approximately between 9 and 10 digits in the decimal part of the number (9 or 10 digits of precision).
Usage example¶
Oracle¶
Result¶
Snowflake¶
Result¶
Known Issues¶
No issues were found.
Related EWIs¶
SSC-FDM-OR0033: DBMS_RANDOM.VALUE Built-In Package precision is lower in Snowflake.