So i have a procedure that i’m currently in the process of debugging and i’ve narrowed it down to this select statement.
Note: where the to_date(”), 3300, 5220 is a representation of what would come from a parameter.
SELECT SHIFT_ID_PK, SHIFT_NAME_FK,
SHIFT_START_DAY, SHIFT_START_TIME,
SHIFT_END_DAY, SHIFT_END_TIME,
SITE_ID_FK, SHIFT_DAY_ID,
STARTOFFSET, ENDOFFSET,
TO_TIMESTAMP_TZ((TO_DATE('3/13/2012 7:00 ', 'mm/dd/yyyy HH:MI:SS am') - (3300 / 24 / 60)) + (STARTOFFSET / 24 / 60), 'YYYY-MM-DD HH:MI:SS TZH:TZM') AS SHIFT_START_DATE,
TO_TIMESTAMP_tz((TO_DATE('3/14/2012 1:00 ', 'mm/dd/yyyy HH:MI:SS am') - (5220 / 24 / 60)) + (ENDOFFSET / 24 / 60), 'YYYY-MM-DD HH:MI:SS TZH:TZM') AS SHIFT_END_DATE
from shift_tbl
WHERE
ENDOFFSET >= 3300
AND STARTOFFSET < 5220
order by shift_start_date asc, shift_end_date;
Now what this is suppose to do, is take the parameter which is a timestamp and subtract an offset value.
this value represents the number of minutes that has gone by during the week where sunday at midnight = 0. (So if it was monday at midnight the offset would = 1440).
when the offset is subtracted from the parameter, you then get the beginning of the week. You then get the offset value from the table which was already predetermined and add that value to the start of the week to obtain the timestamp.
This is done in order to get the start date and end date of a shift.
now below you will see and example of a result set that would come from this:
SHIFT_ID_PK SHIFT_NAME_FK SHIFT_START_DAY SHIFT_START_TIME SHIFT_END_DAY SHIFT_END_TIME SITE_ID_FK SHIFT_DAY_ID STARTOFFSET ENDOFFSET **SHIFT_START_DATE SHIFT_END_DATE**
6146 6206 3 23:00 4 7:00 2450 3 4260 4740 **11-MAR-13 11.00.00.000000000 PM -05:00 11-MAR-14 07.00.00.000000000 PM -05:00**
now my problem is that my shift_start_date and shift_end_date come out as the same value like so
SHIFT_ID_PK SHIFT_NAME_FK SHIFT_START_DAY SHIFT_START_TIME SHIFT_END_DAY SHIFT_END_TIME SITE_ID_FK SHIFT_DAY_ID STARTOFFSET ENDOFFSET **SHIFT_START_DATE SHIFT_END_DATE**
6146 6206 3 23:00 4 7:00 2450 3 4260 4740 **11-MAR-13 11.56.00.000000000 PM -05:00 11-MAR-13 11.56.00.000000000 PM -05:00**
The values marked with
**.....**
are the values i am talking about.
I’ve tried several different things to fix this problem, however nothing i’ve done has worked, so i’m figuring i am just missing something very simple that is causing this problem.
any help or suggestions are greatly appreciated. Thank you.
TO_TIMESTAMP_TZexpects aVARCHAR2for its first parameter; you are passing it aDATE. Therefore, behind the scenes, Oracle is doing an implicitTO_CHARconversion on yourDATEthat is causing you to lose precision in it, to the extent that the two originally different values are made the same.Try first surrounding your
DATEwith aTO_CHARsupplied with an explicit format, then pass that toTO_TIMESTAMP_TZ. Something like:Hope this helps.