我有一个时间格式:20020320000000,现在用to_date('20020320000000','yyyy-mm-dd hh24:mi:ss')转换后变成了
2002-03-20,如果用2010-10-10 10:10:10来比较大小的时候,会报ORA-01861: 文字与格式字符串不匹配这种问题请问怎么处理?
2002-03-20,如果用2010-10-10 10:10:10来比较大小的时候,会报ORA-01861: 文字与格式字符串不匹配这种问题请问怎么处理?
调试欢乐多
to_date('2010-10-10 10:10:10','yyyy-mm-dd hh24:mi:ss')
SELECT To_Char(To_Date('20020320000000'),'yyyy-mm-dd hh24:mi:ss') FROM dual;SELECT To_Char(To_Date('2010-10-10 10:10:10'),'yyyy-mm-dd hh24:mi:ss') FROM dual;
时间和时间是可以比较的,
select * from
(select to_date('20020320000000','yyyy-mm-dd hh24:mi:ss') a from dual) where a < to_date('2010-10-10 10:10:10','yyyy-mm-dd hh24:mi:ss')
select a,b,c from tb where 1=1 and SLDW='320891550000' and
to_date(SLSJ,'yyyy-mm-dd hh24:mi:ss')>=to_date('2010-01-01 00:00:00','yyyy-mm-dd hh24:mi:ss') and
to_date(SLSJ,'yyyy-mm-dd hh24:mi:ss')<=to_date('2010-01-10 00:00:00','yyyy-mm-dd hh24:mi:ss')这个sql语句有问题吗?slsj这个字段全是20020320000000格式的字符串
WHERE to_date('20020320000000','yyyy-mm-dd hh24:mi:ss')>=to_date('2010-01-01 00:00:00','yyyy-mm-dd hh24:mi:ss') and
to_date('20020320000000','yyyy-mm-dd hh24:mi:ss')<=to_date('2010-01-10 00:00:00','yyyy-mm-dd hh24:mi:ss')
无报错,因不满足where条件,没有输出。
是不是字段SLSJ下,有一个数据转换不过来,所以报错了?
if to_date('20020320000000','yyyy-mm-dd hh24:mi:ss')>to_date('2010-10-10 10:10:10','yyyy-mm-dd hh24:mi:ss')
then dbms_output.put_line('ok');
elsif to_date('20020320000000','yyyy-mm-dd hh24:mi:ss')<=to_date('2010-10-10 10:10:10','yyyy-mm-dd hh24:mi:ss')
then dbms_output.put_line('error');
end if;
end;同类型才能比较
--同类型才能比较
begin
if to_date('20020320000000','yyyy-mm-dd hh24:mi:ss')>to_date('2010-10-10 10:10:10','yyyy-mm-dd hh24:mi:ss')
then dbms_output.put_line('ok');
elsif to_date('20020320000000','yyyy-mm-dd hh24:mi:ss')<=to_date('2010-10-10 10:10:10','yyyy-mm-dd hh24:mi:ss')
then dbms_output.put_line('error');
end if;
end;