Last active
August 29, 2015 14:06
-
-
Save brimston3/1dc4b195508024850307 to your computer and use it in GitHub Desktop.
NOT TESTED!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE | |
FUNCTION date_if_possible(v1 IN VARCHAR2) | |
RETURN DATE AS | |
dte_corrected DATE; | |
BEGIN | |
dte_corrected = to_date( | |
to_char(to_number(regexp_substr(v1,'[^,]+', 15, 1)) - 100) || | |
lpad(to_char(to_number(regexp_substr(v1,'[^,]+', 15, 2)) - 100),2,'0') || | |
lpad(regexp_substr(v1,'[^,]+', 15, 3),2,'0') || | |
lpad(regexp_substr(v1,'[^,]+', 15, 4),2,'0'), | |
'YYYYMMDD'); | |
RETURN dte_corrected; | |
EXCEPTION | |
RETURN null; | |
END | |
BEGIN | |
UPDATE me.occasionally_corrupt_table a | |
SET a.dte_time_period = date_if_possible(dump(a.dte_time_period)) | |
WHERE to_char(a.dte_time_period,'YYYYMMDD') = '00000000' | |
AND date_if_possible(dump(a.dte_time_period)) IS NOT NULL; | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
would totally date