split string based on character position in ORACLE 11g SQL

∥☆過路亽.° 提交于 2019-12-11 11:16:15

问题


I'm using oracle 11g sql developer

I have a varchar2 column with dates as 0523 (mmDD).

I want to convert them to a date column and have them look like 23-05 (dd-mm)..

Any ideas?


回答1:


Well, you can do string operations directly to get the format you want:

substring(c, 3, 2)||'-'||substring(c, 1, 2)

To convert to a date, you can use:

to_date('2012'||c, 'YYYYMMDD')

To convert a date back to the form you want:

to_char(<date>, 'DD-MM')


来源:https://stackoverflow.com/questions/11231161/split-string-based-on-character-position-in-oracle-11g-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!