With子句或子查询因子子句为日期提供错误

时间:2017-03-21 08:51:40

标签: sql oracle oracle11g

我正在尝试将日期参数传递给with子句并获得以下错误。如果我传递硬核值,则查询检索值。

查询:

WITH reg AS
     (  SELECT  'I' AS OPERATION,
        CPIX.ID_VALUE AS ID_VALUE,
        GLOBAL_ID AS GLOBAL_ID,
        DISPLAY_VALUE AS ONEKEY_ID,
        (SELECT  N.NAME FROM NUC_CFG_REGION N WHERE REGION_ID=CPIX.REGION_ID) AS COUNTRY,
         CRTN_DT AS FROM_DATE,
         TRUNC(SYSDATE) AS TO_DATE1

    FROM CUS_PRIMARY_ID_XREF CPIX
    WHERE   trunc(crtn_dt)>to_date(&start_date,'YYYY-MM-DD') and trunc(crtn_dt)<to_date(&end_date,'YYYY-MM-DD')
     )
    SELECT Operation,
       country,
       count(onekey_id) Tot_onekey_cnt,
       FROM_DATE,
       TO_DATE1
    from reg
    group by ROLLUP(country),Operation,FROM_DATE,TO_DATE1
    HAVING  (GROUPING(country)=0 )

错误:

  

ORA-01840:日期格式的输入值不够长

2 个答案:

答案 0 :(得分:1)

必须是'&start_date'(在单引号内)

&variable将简单地用输入值替换,如宏。

答案 1 :(得分:0)

除非提供正确的输入日期格式,否则查询将正常工作。在您的情况下,输入日期必须符合掩码,即'YYYY-MM-DD'。

希望这有帮助。