[英]Error comparing dates in oracle sql query
I am writing a sql query where I need to convert varchar column value to date and use it in where clause. 我正在写一个SQL查询,我需要将varchar列值转换为日期并在where子句中使用它。
Following is the query that I am trying; 以下是我正在尝试的查询;
SELECT *
FROM
( SELECT DISTINCT t1.record_id,
t1.column_name,
t1.value,
t1.row_index,
t1.start_date,
t1.end_date,
t2.value AS val
FROM sf_monthly_fin_exp t1,
sf_monthly_fin_exp t2
WHERE t1.row_index = t2.row_index
AND t1.generated_report_id = t2.generated_report_id
AND t1.generated_report_id =11700
AND t2.column_name = 'Date'
AND t2.value <> 'Total'
AND t1.column_name = 'xyz'
ORDER BY t1.row_index
)
WHERE TO_DATE(val, 'dd/mm/YYYY') = TO_DATE('05/01/2014', 'dd/mm/YYYY');
I am converting the value to date type while comparing but it is giving me following error; 我在比较时将值转换为日期类型,但出现以下错误;
ORA-01858: a non-numeric character was found where a numeric was expected
01858. 00000 - a non-numeric character was found where a numeric was expected.
What am I doing wrong in the query, any help would be much appreciated. 我在查询中做错了什么,任何帮助将不胜感激。
You try convert "t2.value" to date. 您尝试将“ t2.value”转换为日期。 Probably you would like convert "t1.value":
可能您想转换“ t1.value”:
WHERE TO_DATE(value, 'dd/mm/YYYY') = TO_DATE('05/01/2014', 'dd/mm/YYYY');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.