Notice
Recent Posts
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

IT'S YU

[Oracle] ORA-01861: 리터럴이 형식 문자열과 일치하지 않음 오류 본문

DB/Oracle

[Oracle] ORA-01861: 리터럴이 형식 문자열과 일치하지 않음 오류

자석 2022. 12. 7. 13:38

ORA-01861: 리터럴이 형식 문자열과 일치하지 않음


위 오류는 날짜형식 컬럼이 SELECT절에서 사용되지 않았더라도 WHERE절에서 조건 사용될 경우 발생할 수 있음,,


ex>
데이터타입이 VARCHAR2(30 BYTE), 실제 데이터값은 '9999-12-31'인 컬럼 'A_DATE'에 대하여 SQL 작성시

---> 수정 전 : 
SELECT *
FROM TEST_TABLE
WHERE 1=1
            AND A_DATE >= TO_DATE('20210101','YYYYMMDD')
            AND A_DATE < TO_DATE('20210102','YYYYMMDD')
            
결과: 아래와 같은 오류발생 
ORA-01861: 리터럴이 형식 문자열과 일치하지 않음
01861. 00000 -  "literal does not match format string"
*Cause:    Literals in the input must be the same length as literals in
           the format string (with the exception of leading whitespace).  If the
           "FX" modifier has been toggled on, the literal must match exactly,
           with no extra whitespace.
*Action:   Correct the format string to match the literal.

---> 수정 후 :
SELECT *
FROM TEST_TABLE
WHERE 1=1
     AND A_DATE >=  '2021-01-01'
     AND A_DATE <  '2022-01-01'