JSDATE UDF
Description
This custom UDF is added to avoid runtime exceptions caused by format differences when casting strings to DATE, inside procedures and functions.
Custom UDF overloads
JS_DATE_UDF(datestr)
It creates a DATE from a STRING.
Parameters
DATESTR: A
STRINGthat represents aDATEwith a specific format.
CREATE OR REPLACE FUNCTION PUBLIC.JS_DATE_UDF(DATESTR STRING)
RETURNS DATE LANGUAGE SQL IMMUTABLE AS
$$
SELECT TO_DATE(DATESTR,'YYYY-MM-DD"T"HH24:MI:SS.FF')
$$;Oracle
--Create Table
CREATE TABLE jsdateudf_table( col1 DATE );
--Create Procedure
CREATE OR REPLACE PROCEDURE jsdateudf_proc ( par1 DATE )
IS
BEGIN
INSERT INTO jsdateudf_table VALUES(par1);
END;
--Insert Date
CALL jsdateudf_proc('20-03-1996');
--Select
SELECT * FROM jsdateudf_table;COL1 |
-----------------------+
1996-03-20 00:00:00.000|Snowflake
Known Issues
1. Oracle DATE contains TIMESTAMP
Take into consideration that Oracle DATE contains an empty TIMESTAMP (00:00:00.000), while Snowflake DATE does not. SnowConvert allows transforming DATE to TIMESTAMP with the SysdateAsCurrentTimestamp flag.
Related EWIs
MSCEWI1020: CUSTOM UDF INSERTED.
Last updated
Was this helpful?