SUBSTR Function
Translation reference for DBMS_RANDOM.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)
This built-in function is replaced with Snowflake SUBSTR function. However, there are some differences.
Syntax
DBMS_LOB.SUBSTR (
lob_loc IN BLOB,
amount IN INTEGER := 32767,
offset IN INTEGER := 1)
RETURN RAW;
DBMS_LOB.SUBSTR (
lob_loc IN CLOB CHARACTER SET ANY_CS,
amount IN INTEGER := 32767,
offset IN INTEGER := 1)
RETURN VARCHAR2 CHARACTER SET lob_loc%CHARSET;
DBMS_LOB.SUBSTR (
file_loc IN BFILE,
amount IN INTEGER := 32767,
offset IN INTEGER := 1)
RETURN RAW;Function overloads
DBMS_LOB.SUBSTR('string', amount, offset)
Usage example
Oracle
Snowflake
DBMS_LOB.SUBSTR(BLOB, amount, offset)
Usage example
Note: 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
Snowflake
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
Snowflake
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.
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
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.
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
MSCEWI3105: Additional Work Is Needed For BFILE Column Usage
MSCEWI3121: Using DBMS_LOB.SUBSTR built-in package with a BFILE column is not supported in Snowflake.
Last updated
Was this helpful?