使用to_date函数将字符串转换为日期时出现ORA-01858错误

时间:2013-08-30 10:12:27

标签: oracle plsql date-conversion ora-01858

我正在尝试使用PL / SQL中的以下代码将字符串转换为日期:

BEGIN
   vfrom := TO_DATE ('20/08/2013', 'dd/mm/yyyy');
   vto := TO_DATE ('30/08/2013', 'dd/mm/yyyy');

   OPEN L_CURSOR FOR
      SELECT DSAT.ORGANIZATION_ID,
             APPS.DAW_INV_ORG_NAME (DSAT.ORGANIZATION_ID) ORGANIZATION_NAME,
             APPS.DAW_CAT_NAME (MC.SEGMENT4) PRODUCT,
             TRUNC (NVL (DSAT.SCH_END_DATE, DSAT.SCH_START_DATE))
                TRANSACTION_DATE,
             TO_CHAR (NVL (DSAT.SCH_END_DATE, DSAT.SCH_START_DATE),
                      'MM-YYYY')
                MONTH,
             DSAT.ITEM_SEGMENTS ITEM_CODE,
             DSAT.ITEM_DESCRIPTION,
             DSAT.CURRENT_FORECAST_QUANTITY PLAN_QTY
        FROM APPS.DAW_SCPDB_ASCP_TPP_V DSAT,
             APPS.MTL_ITEM_CATEGORIES MIC,
             APPS.MTL_CATEGORIES MC
       WHERE     NVL (SCH_END_DATE, SCH_START_DATE) BETWEEN '$(vfrom)'
                                                        AND '$(vto)'
             AND MIC.CATEGORY_SET_ID = 1100000061         --- PLANING CATEGORY
             AND MC.CATEGORY_ID = MIC.CATEGORY_ID
             AND DSAT.INVENTORY_ITEM_ID = MIC.INVENTORY_ITEM_ID
             AND DSAT.ORGANIZATION_ID = MIC.ORGANIZATION_ID
             AND DSAT.FORECAST_SET = '$(vForecastSetDPL2)'; --- Need to Update it on Monthly Basis;
END PorductPlanningForecast;

错误发生在

  

ORA-01858:找到一个非数字字符,其中第29行预期有数字

包括打开查询的游标。我已经检查了NSL参数并将日期设置为to_Date函数中的格式,在整个互联网上搜索但我无法弄明白。请帮忙。

1 个答案:

答案 0 :(得分:1)

在行WHERE NVL(SCH_END_DATE,SCH_START_DATE) BETWEEN '$(vfrom)' and '$(vto)'中,您将字符串'$(from)'隐式转换为日期。那不行。

假设from和to被声明为date,该行应该是这样的WHERE NVL(SCH_END_DATE,SCH_START_DATE) BETWEEN vfrom and vto