Skip to content

Instantly share code, notes, and snippets.

@brimston3
Last active August 29, 2015 14:06
Show Gist options
  • Save brimston3/1dc4b195508024850307 to your computer and use it in GitHub Desktop.
Save brimston3/1dc4b195508024850307 to your computer and use it in GitHub Desktop.
NOT TESTED!
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
@brimston3
Copy link
Author

would totally date

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment