Guest User

Untitled

a guest
Apr 27th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. update tbl set columnA = columnB
  2.  
  3. create or replace function is_date (
  4. P_String in varchar2
  5. , P_Date_Format in varchar2
  6. ) return number is
  7.  
  8. l_date date;
  9.  
  10. begin
  11.  
  12. l_date := to_date(P_String, P_Date_Format);
  13.  
  14. return 1;
  15. exception when others then
  16. return 0;
  17. end;
  18.  
  19. update my_table
  20. set date_column = to_date(char_column, 'yyyy-mm-dd')
  21. where is_date(char_column, 'yyyy-mm-dd') = 1
  22.  
  23. update my_table
  24. set date_column = case when is_date(char_column, 'yyyy-mm-dd') = 1
  25. then to_date(char_column, 'yyyy-mm-dd')
  26. when is_date(char_column, 'yyyymmdd') = 1
  27. then to_date(char_column, 'yyyymmdd')
  28. ...
  29. snip
  30. ...
  31. end
  32.  
  33. UPDATE tbl
  34. SET columnA = DECODE(type, '1', DECODE(INSTR(columnB, '-'), 5, TO_DATE(columnB, 'YYYY-MM-DD'),
  35. TO_DATE(columnB, 'MM/DD/YYYY')),
  36. TO_DATE(columnB, 'MMDDYYYY'));
Add Comment
Please, Sign In to add comment