Home » SQL & PL/SQL » SQL & PL/SQL » ORA-01840: input value not long enough fro date format. (Oracle 11 g)
ORA-01840: input value not long enough fro date format. [message #597674] |
Mon, 07 October 2013 09:18  |
 |
jayant.tripathi
Messages: 8 Registered: October 2013
|
Junior Member |
|
|
Hi,
I am executing an SQL query using a JAVA program. This is running fine for all the dates except last day of any month.
When i enter 20130205 it is working fine but for 30 or 31, it is throwing this exception.
Format of the date is yyyymmdd.
Can you please help me with this?
SELECT DISTINCT :SPID, t1.nodename nodename, t1.gdate, t1.gtime,
t1.gdate_time, t1.ndd_mw, t1.ndd_mv, nvl(t1.fms_mw,0)+t2.fms_mw+mw, nvl(t1.fms_mv,0)+t2.fms_mv+mv,
t1.nddraw_mw, t1.nddraw_mv
FROM tmp_ndd_nddraw_fms_data t1, tmp_ndd_nddraw_fms_data t2, (
WITH min_max_date as(select min(gdate) min_date,max(gdate) max_date from tmp_ms_data),
maps as( select game from unmetmap where gspid=:SPID),
t AS
(
SELECT TO_CHAR (f.target_datetime, 'YYYYmmdd') gdate,
TO_CHAR (f.target_datetime, 'HH24mi') gtime,
SUM (f.mean_frcstd_mw) mw
FROM pkd_dt f, wgen w,maps m,min_max_date d
WHERE f.gen_id = w.gen_id
AND w.gen_name =m.gen_name
AND f.target_datetime BETWEEN TO_DATE (d.min_date,
'yyyymmddhh24mi'
)
- 1 / 48
AND TO_DATE (d.max_date + 1,
'yyyymmddhh24mi'
)
+ 1 / 48
GROUP BY f.target_datetime
ORDER BY TO_CHAR (f.target_datetime, 'YYYYmmdd'),
TO_CHAR (f.target_datetime, 'HH24mi')),
m_w AS
(
SELECT gdate,
DECODE (gtime,
2330, 2400,
TO_CHAR ( TO_DATE (LPAD (gtime, 4, '000'), 'HH24mi')
+ 1 / 48,
'HH24MI'
)
) gtime,
mw
FROM (SELECT gdate, gtime + 0 gtime, mw
FROM t t1
UNION
SELECT t1.gdate, t1.gtime + 30 gtime, (t1.mw + t2.mw) / 2
FROM t t2, t t1
WHERE (t1.gdate = t2.gdate AND t1.gtime + 100 = t2.gtime)
OR ( t1.gdate + 1 = t2.gdate
AND t1.gtime = 2300
AND t2.gtime = 0
)),min_max_date
WHERE gdate BETWEEN min_date AND max_date),
t2 AS
(
SELECT TO_CHAR (f.target_datetime, 'YYYYmmdd') gdate,
TO_CHAR (f.target_datetime, 'HH24mi') gtime,
SUM (f.f_mvar) mw
FROM extdata f, wger w,maps m,min_max_date d
WHERE f.gen_id = w.gen_id
AND w.gen_name =m.gen_name
AND f.target_datetime BETWEEN TO_DATE (min_date,
'yyyymmddhh24mi'
)
- 1 / 48
AND TO_DATE (max_date + 1,
'yyyymmddhh24mi'
)
+ 1 / 48
GROUP BY f.target_datetime
ORDER BY TO_CHAR (f.target_datetime, 'YYYYmmdd'),
TO_CHAR (f.target_datetime, 'HH24mi')),
wind_mv AS
(
SELECT gdate,
DECODE (gtime,
2330, 2400,
TO_CHAR ( TO_DATE (LPAD (gtime, 4, '000'), 'HH24mi')
+ 1 / 48,
'HH24MI'
)
) gtime,
mw mv
FROM (SELECT gdate, gtime + 0 gtime, mw
FROM t2 t1
UNION
SELECT t1.gdate, t1.gtime + 30 gtime, (t1.mw + t2.mw) / 2
FROM t2 t2, t2 t1
WHERE (t1.gdate = t2.gdate AND t1.gtime + 100 = t2.gtime)
OR ( t1.gdate + 1 = t2.gdate
AND t1.gtime = 2300
AND t2.gtime = 0
)),min_max_date
WHERE gdate BETWEEN min_date AND max_date)
(SELECT wmw.gdate, wmw.gtime, nvl(mw,0)mw, nvl(mv,0) mv
FROM w_mw, w_mv
WHERE wind_mw.gdate = wind_mv.gdate(+) AND wind_mw.gtime = wind_mv.gtime(+))) T3
WHERE t1.gdate = t2.gdate
AND t1.gtime = t2.gtime
and t1.gtime=t3.gtime
and t1.gdate=t3.gdate
AND t1.nodename = t2.nodename || 'DW'
AND t1.nodename LIKE '%DW'
AND t1.spid = 0
*BlackSwan added {code} tags. Please do so yourself in the future.
[Updated on: Mon, 07 October 2013 09:22] by Moderator Report message to a moderator
|
|
|
|
|
|
|
|
|
Re: ORA-01840: input value not long enough fro date format. [message #597687 is a reply to message #597685] |
Mon, 07 October 2013 10:33   |
cookiemonster
Messages: 13967 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
Michel Cadot wrote on Mon, 07 October 2013 16:25
Change "TO_DATE (max_date + 1, 'yyyymmddhh24mi')" by "TO_DATE (to_char(max_date,'fm000000000000'), 'yyyymmddhh24mi') + 1"
Given the format mask, missing leading zeros shouldn't be an issue unless the dates pre-date 1000 A.D.
on the other hand:
SQL> SELECT TO_DATE (201310071259, 'yyyymmddhh24mi') FROM dual;
TO_DATE(201310071259,'YYYYMMDD
------------------------------
07/10/2013 12:59:00
SQL> SELECT TO_DATE (201310071259 + 1, 'yyyymmddhh24mi') FROM dual;
SELECT TO_DATE (201310071259 + 1, 'yyyymmddhh24mi') FROM dual
ORA-01851: minutes must be between 0 and 59
SQL>
That code is a bug waiting to happen, but I don't think it's the bug the OP is currently hitting.
|
|
|
|
|
|
|
|
|
|
|
Re: ORA-01840: input value not long enough fro date format. [message #597808 is a reply to message #597806] |
Tue, 08 October 2013 09:27   |
cookiemonster
Messages: 13967 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
jayant.tripathi wrote on Tue, 08 October 2013 15:07i have changed the to_date(d.maxdate +1, 'yyyymmddhhmiss') to to_date(d.maxdate, 'yyyymmddhhmiss') and it worked.
I hope you changed it to to_date(d.maxdate, 'yyyymmddhhmiss') + 1.
Though that means the original was adding a second and the new version is adding a day.
Plus your query above uses 'yyyymmddhhmi' (no ss) so that's really confused things.
jayant.tripathi wrote on Tue, 08 October 2013 15:07
To_char is also not working.
you have several, which one?
jayant.tripathi wrote on Tue, 08 October 2013 15:07
It is giving me Incorrect query error.
that's not a valid oracle error message and tells us nothing useful.
We are not stood over your shoulder, we can't see what code you're running, we don't have access to your tables or data and we don't actually know what the query is supposed to do. We only know what you tell us. So if you want help fixing it you need to supply more information.
|
|
|
|
|
Goto Forum:
Current Time: Sat Jun 07 02:28:42 CDT 2025
|