[英]SQL Query to Convert 2019/05/21 00:00:00 format to 21-JUN-19(i.e., DD-MON-YY)
I have a date format "2019/05/21 00:00:00" and I need to convert this into "21-JUN-19" using SQL. 我的日期格式为“ 2019/05/21 00:00:00”,我需要使用SQL将其转换为“ 21-JUN-19”。 How can I convert this?
我该如何转换呢?
Assuming that the source value is a string, then 假设源值为字符串,则
to_date
, with appropriate format mask) to_date
,使用适当的格式掩码) to_char
, again with appropriate format mask) to_char
,再次使用适当的格式掩码) By the way, why are you converting 2019/ 05 /21 into jun ? 顺便说一句,你为什么将2019/05/21形成君 ? It can be done, no problem (
ADD_MONTHS
does that), just wondering whether you did it intentionally or by mistake. 可以做到,没问题(
ADD_MONTHS
做到这一点),只是想知道您是故意还是错误地做到了。
SQL> select to_char(to_date('2019/05/21 00:00:00', 'yyyy/mm/dd hh24:mi:ss'), 'dd-mon-yy') result from dual;
RESULT
---------
21-may-19
SQL>
You can use substr()
and to_date()
: 您可以使用
substr()
和to_date()
:
select to_date(substr('2019/05/21 00:00:00', 1, 10), 'YYYY/MM/DD')
from dual;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.