我有一个名为StartDate的列,其中包含以下格式的日期:03-03-2012 15:22
我需要的是将其转换为日期。应该是这样的:DD / MM / YYYY
我没有成功尝试过的是:
select p1.PA_VALUE as StartDate,p2.PA_VALUE as EndDate from WP_Work p LEFT JOIN PARAMETER p1 on p1.WP_ID=p.WP_ID AND p1.NAME = 'StartDate' LEFT JOIN PARAMETER p2 on p2.WP_ID=p.WP_ID AND p2.NAME = 'Date_To' WHERE p.TYPE = 'EventManagement2' AND TO_DATE(p1.PA_VALUE,'DD/MM/YYYY') >= TO_DATE('25/10/2012','DD/MM/YYYY') AND TO_DATE(p2.PA_VALUE,'DD/MM/YYYY') <= TO_DATE('26/10/2012','DD/MM/YYYY')
有没有办法做到这一点?
EDIT1:PA_VALUE列是:VARCHAR2
当您将字符串转换为日期时,需要将日期掩码与字符串中的格式相匹配。这包括一个时间元素,您需要使用截断进行删除:
原文链接:https://www.f2er.com/oracle/205989.htmlselect p1.PA_VALUE as StartDate,p2.PA_VALUE as EndDate from WP_Work p LEFT JOIN PARAMETER p1 on p1.WP_ID=p.WP_ID AND p1.NAME = 'StartDate' LEFT JOIN PARAMETER p2 on p2.WP_ID=p.WP_ID AND p2.NAME = 'Date_To' WHERE p.TYPE = 'EventManagement2' AND trunc(TO_DATE(p1.PA_VALUE,'DD-MM-YYYY HH24:MI')) >= TO_DATE('25/10/2012','DD/MM/YYYY') AND trunc(TO_DATE(p2.PA_VALUE,'DD-MM-YYYY HH24:MI')) <= TO_DATE('26/10/2012','DD/MM/YYYY')