web developer๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป

[Oracle] ORA-01861: ๋ฆฌํ„ฐ๋Ÿด์ด ํ˜•์‹ ๋ฌธ์ž์—ด๊ณผ ์ผ์น˜ํ•˜์ง€ ์•Š์Œ ๋ณธ๋ฌธ

DB

[Oracle] ORA-01861: ๋ฆฌํ„ฐ๋Ÿด์ด ํ˜•์‹ ๋ฌธ์ž์—ด๊ณผ ์ผ์น˜ํ•˜์ง€ ์•Š์Œ

natrue 2021. 5. 25. 23:13
728x90
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.

์›์ธ  

DATE ํƒ€์ž…์— Stringํ˜•์˜ ๋ฌธ์ž์—ด์„ ๋„ฃ์œผ๋ ค ํ•˜๊ฑฐ๋‚˜ DATEํ˜•๊ณผ Stringํ˜•์„ ๋น„๊ตํ•˜๋ ค ํ•  ๋•Œ ๋ฐœ์ƒํ•˜๋Š” ์—๋Ÿฌ.

ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•  

1. date ํƒ€์ž…์„ String์œผ๋กœ ๋ณ€๊ฒฝํ•œ๋‹ค.

TO_CHAR : ๋‚ ์งœ ๋˜๋Š” ์ˆซ์ž๋ฅผ ๋ฌธ์ž๋กœ ๋ณ€๊ฒฝ

TO_CHAR(SYSDATE, 'YYYYMMDD') 

2. String ํƒ€์ž…์„ date ํƒ€์ž…์œผ๋กœ ๋ณ€๊ฒฝํ•œ๋‹ค.

TO_DATE : ๋ฌธ์žํ˜• ๋ฐ์ดํ„ฐ๋ฅผ ๋‚ ์งœ ๋ฐ์ดํ„ฐํ˜•์œผ๋กœ ๋ณ€๊ฒฝ 

TO_DATE('20210526', 'YYYYMMDD')