Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

An issue has been brought to my attention recently that was to do with the to_date function returning an ORA-01840 error for certain values. This prompted an investigation which ultimately proved that it was a data issue, however I decided to put together a workaround for future reference anyway.

The error being thrown was:
 Error
ORA-01840: input value not long enough for date format
01840. 00000 - "input value not long enough for date format"


That's fairly straight forward, it just means that the date I am trying to convert doesn't have enough precision for the format that I am trying to convert it to. The SQL below demonstrates this...
 SQL
select to_date('2016', 'YYYYMMDDHH24MISS')
from dual;


Interestingly the error disappears when I add a month and day to my date value i.e. 20160101 is OK even though my format expects hours, minutes and seconds too.

My workaround takes advantage of the above find by padding the date up to 8 characters (yyyymmdd) as required. It consists of two rpad operations, one for the day and one for the month to cater for inputs of the 'yyyy' and 'yyyymm' formats.

This is the end result...
 SQL
select to_date(rpad(rpad('2016', 6, '01'), 8, '01'), 'YYYYMMDDHH24MISS')
from dual;




It's not the best solution but will get you out of a bind if you really need to pad dates like this.

-i

Please leave your comments or feedback below!
comments powered by Disqus
Other posts you may like...
Hi! You can search my blog here ⤵
Or browse the recent top tags...

Recent Blog Posts

Coherence and weblogic.xml in different types of J2EE web app deployments

Atari Lynx repair - Part 5 - McWill LED screen mod installation

Atari Lynx repair - Part 4 - screen cover replacement

Atari Lynx repair - Part 3 - broken speaker replacement

Atari Lynx repair - Part 2 - re-capping the motherboard

Atari Lynx repair - Part 1 - introduction and case disassembly

jPhotoFrame updated to version 0.3.1 with an image rotation correction utility

iOS 11 pre-GM mini review before it gets revealed next week

Why you should never use Java enums as keys with Oracle Coherence caches

Hacking the VideoPak 7inch promotional brochure to work as a digital photo frame

Recent Galleries

Atari Lynx repair - Part 5 - McWill LED screen mod installation

Atari Lynx repair - Part 4 - screen cover replacement

Atari Lynx repair - Part 2 - re-capping the motherboard

Atari Lynx repair - Part 3 - broken speaker replacement

Atari Lynx repair - Part 1 - introduction and case disassembly

Building a custom Atari Lynx game box storage shelf unit in a day

Protecting old Atari Lynx game boxes with snug fit plastic sleeves

Monument Valley 2 is released and does not disappoint

Space Food - Chocolate Ice Cream with Chocolate Chips

Legeod Star Wars AT-DP kit

Blogs and Friends

Matt Moores Blog
Georgi's FlatPress Guide
Perplexing Permutations
The Security Sleuth
Ilia Rogatchevski
Travelling Fairy

Blog Activity

Blog Activity