ORA - 01722使用Partition Over和To_Char时出错

时间:2014-10-06 18:20:56

标签: sql oracle performance reporting-services ssrs-2008

我在SQL世界中相对较新,我正在努力获得尽可能多的知识。这个让我难过。我们所有的数据都是在Oracle数据库中编译的,但我们创建的报告是从SSRS到Visual Studio 2005创建的。这就是问题所在。我有一个查询,通过使用将日期转换为字符串的参数来帮助分隔数据,以便用户可以选择报告顶部的日期。对此的查询是:

select type_type,
        RCD_REASON,
        rc.description,
        MATERIAL_ID,
        USERID,
        DATETIME_SCRAPPED,
        ORDER_NUMBER,
        TRIMDATE,
        SUBSTR(SALES_ORDER,3,8) || '-' || SUBSTR(SOL_LINE_NUMBER,3,4) AS SalesOrder,
        QTY,
        COMPONENT_MATERIAL_ID 
from WORKCELL.history hh 
inner join WORKCELL.reason_codes rc
  on hh.rcd_reason = rc.reason
where rc.type_type in ('FAB','TRM') AND TO_CHAR(DATETIME_SCRAPPED,'YYYYMMDD') between to_char(:FromDate,'YYYYMMDD') AND to_char(:ToDate,'YYYYMMDD')

FromDate和ToDate是参数。

我对查询进行了一些调整:

select type_type,
           RCD_REASON,
           rc.description,
           MATERIAL_ID,
           USERID,
           DATETIME_SCRAPPED,
           ORDER_NUMBER,
           TRIMDATE,
           SUBSTR(SALES_ORDER,3,8) || '-' || SUBSTR(SOL_LINE_NUMBER,3,4) AS SalesOrder,
           QTY,
           COMPONENT_MATERIAL_ID , 
           row_number() over (partition by  SALES_ORDER, ORDER_NUMBER order by DATETIME_SCRAPPED) as rn

    from WORKCELL.history hh 
    inner join WORKCELL.reason_codes rc
    on hh.rcd_reason = rc.reason
    where rc.type_type in ('FAB','TRM') 
   AND to_char(DATETIME_SCRAPPED,'YYYYMMDD') between to_char(:FromDate,'YYYYMMDD') AND to_char(:ToDate,'YYYYMMDD')

现在我因“无效号码”而收到此ORA-01722错误。任何人都可以解释为什么会这样吗?当我对日期进行硬编码时,查询运行正常,但由于某种原因,参数现在会破坏它。是的,我必须在查询SSRS中使用这些参数。

0 个答案:

没有答案