我正在编写一个sql查询,我需要将varchar列值转换为date并在where子句中使用它。
以下是我正在尝试的查询;
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');
我在比较时将值转换为日期类型,但它给了我以下错误;
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.
我在查询中做错了什么,非常感谢任何帮助。
答案 0 :(得分:0)
您尝试将“t2.value”转换为日期。可能你想转换“t1.value”:
WHERE TO_DATE(value, 'dd/mm/YYYY') = TO_DATE('05/01/2014', 'dd/mm/YYYY');