During my insertion of case when statement, the oracle will auto insert another ‘0’ behind any fixed number due to my case when.
For example:
INSERT INTO test
(test_date,
testno,
hours)
SELECT '20-OCT-2010',
'1234',
CASE
WHEN Extract(DAY FROM( endtime - starttime )) >= 1 THEN (
Extract(DAY FROM(
endtime - starttime ))
* 24 + Extract
(HOUR FROM(
endtime - starttime
)) )
WHEN starttime IS NULL
AND endtime IS NULL THEN 0
ELSE ( Extract(HOUR FROM( endtime - starttime )) )
END
||''
|| CASE
WHEN endtime IS NULL
AND starttime IS NULL THEN 0
ELSE Extract(MINUTE FROM ( endtime - starttime )) / 60
END AS hours
FROM testtime
My results executed from the above statement:
Test_Date TestNo Hours
20-OCT-2010 1234 140
Expected results:
Test_Date TestNo Hours
20-OCT-2010 1234 14
My data type for hours is number (4,2)
My error is due to that if the starttime and endtime for minute is null, it will auto add an ‘0’ behind it. Even i change the ‘0’ to null, it will still add 0 behind.
May i know is there another way to place the ‘0’ value?
Thanks
Instead of concatenating number-of-hours and number-of-minutes,-divided-by-sixty, you should add them. For example, 3 hours and 0 minutes is
3 + 0 = 3hours, not3 || 0 = 30hours.In other words, change your
||''||to+.