Igor's Blog

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

, ,
About — I'm an enthusiastic software engineer and consultant interested in many fields including J2EE, programming, electronics, 3D printing, video games, wood working and gardening.
See my Resume for more information.
The views expressed in this blog are my own and not those of my employer.
comments powered by Disqus
My other posts you may like...
Programming, DIY, Games, Hacks, Tech and more.
Follow me on...
Current and Past Projects
See my Resume

Subscribe


RSS Feed

My Other Web Sites

Igor and Elise's Travels
Riverside Expressway Cam
300 George St Blogumentary

My Online Tools

UUID to OID Converter
Guru JSON-RPC Tester
Extrudifier Object Designer

Recent Blog Posts

WebLogic package-name element classpath generator script

Using Jersey 2.x as a shared library on WebLogic 12.1.2

Google DFP with AdSense fallback is causing infinite scroll pages to go haywire

Workaround for Mobile Safari scrollTop() not updating during scroll

Skipping execution of Maven plugins that do not have a native skip option

Unmarshalling an XML fragment representing a JAXB object without XmlRootElement

Injecting a ContainerRequestContext into a Jersey entity provider class

Obfuscating PHP source code with Maven and YAK Pro PO

Making use of corner shelves with easy to make slide out draws

Octotree breaks GitLab Issue Boards

Recent Galleries

Space Food - Chocolate Ice Cream with Chocolate Chips

Legeod Star Wars AT-DP kit

DIY spare parts computer build with a RAIDMAX Anura case

Fake 'Lepin' brand Lego packaging

Hardwood garden bench with clear resin void filler

Fixing a 3D printer extruder that stopped heating up

Easily increase disk space in a Lenovo Ideapad 100S 14" laptop with an M.2 SSD

Making a multi-piece 3D printed solder spool holder stand

DIY indoor apartment grow light wiring

Good Friday Electronics fun Easter Bunny LED PCB Kit IBEABU-01.0

Top Categories

Blogs I follow

Matt Moores Blog
Georgi's FlatPress Guide
Perplexing Permutations
The Security Sleuth

Friends

RAWS Parts Online
Alpha Dimensions Hosting
Kristensen Photography
Ilia Rogatchevski
Travelling Fairy

Blog Activity

Blog Activity
Follow me on... 
     
...or subscribe for updates!

Don't show this again