1.两张表tableA,tableB
tableA.value varchar2(120) 这个值有普通值也有日期类型的值问题出现在to_date(tableA.value, 'yyyy-mm-dd')上sql大概为:select t.attr_code,t.value from 
(select b.attr_code, a.value from tableA a, tableB b
where b.attr_id = a.attr_id
and b.attr_code in ('xxxx', 'yyyy')
and a.prod_id = 123
order by a.create_time ) t
where to_date(t.value, ''yyyy-mm-dd') between to_date('2011-09-27', ''yyyy-mm-dd') and to_date('2012-09-27', ''yyyy-mm-dd')内层select单独测试 可以正常查询出结果 都是日期格式的varchar2类型
但是联合测试 报错
ORA-01841: (full) year must be between -4713 and +9999如果用select a.value from tableA a where a.prod_id = 123结果中有非日期类型的数据,但是已经通过 两表关联屏蔽了那些非日期类型数据,按道理应该没有问题了,
不知道神马问题?各位大大帮忙看看。补充,我把那条被屏蔽非日期格式数据删除 ,上面的sql执行成功。百思不得其解

解决方案 »

  1.   

    select b.attr_code, a.value from tableA a, tableB b
    where b.attr_id = a.attr_id
    and b.attr_code in ('xxxx', 'yyyy')
    and a.prod_id = 123
    order by a.create_time你内层的SQL那里有过滤的语句?表tableA 的过滤条件只有prod_id = 123啊
    和你下面的查询过滤条件是一样的啊
    select a.value from tableA a where a.prod_id = 123
    你犯晕了吧
      

  2.   

    select t.attr_code,t.value from  
    (select b.attr_code, a.value from tableA a, tableB b
    where b.attr_id = a.attr_id
    and b.attr_code in ('xxxx', 'yyyy')
    and a.prod_id = 123
    order by a.create_time ) t
    where to_date(t.value, ''yyyy-mm-dd') between to_date('2011-09-27', ''yyyy-mm-dd') and to_date('2012-09-27', ''yyyy-mm-dd')还有你有没看你这语句的执行计划,
    oracle 有可能把你的外层的where 语句给放到内层去执行了
      

  3.   

    写一个函数,判断一下字符串是否符合日期类型
    然后在 where 条件里加一个过滤