TIMESTAMP - TIMESTAMP
дает результат INTERVAL DAY TO SECOND
(не строка) - просто добавьте его к данным эпохи и используйте TO_CHAR
, чтобы получить компонент времени:
SQL Fiddle
Настройка схемы Oracle 11g R2 :
CREATE TABLE EMPLOYEE_LOGIN_TIME(
EMPLOYEE_ID INTEGER,
TIME_IN TIMESTAMP(6) WITH LOCAL TIME ZONE,
TIME_OUT TIMESTAMP(6) WITH LOCAL TIME ZONE,
WORKING_HOUR VARCHAR2(30 BYTE),
PUNCH_DATE DATE,
TIME_OUT_HISTORY VARCHAR2(200 BYTE)
);
INSERT INTO EMPLOYEE_LOGIN_TIME (
EMPLOYEE_ID,
TIME_IN,
TIME_OUT,
WORKING_HOUR,
PUNCH_DATE,
TIME_OUT_HISTORY
)
SELECT 73584,
SYSTIMESTAMP,
SYSTIMESTAMP + INTERVAL '+000000000 01:14:00.771000000' DAY TO SECOND,
NULL,
SYSDATE,
NULL
FROM DUAL;
Запрос 1 :
UPDATE EMPLOYEE_LOGIN_TIME
SET WORKING_HOUR = TO_CHAR(
DATE '0001-01-01' + ( TIME_OUT- TIME_IN ),
'HH24:MI:SS'
)
WHERE EMPLOYEE_ID= 73584
AND PUNCH_DATE >= TRUNC(SYSDATE)
AND PUNCH_DATE < TRUNC(SYSDATE) + INTERVAL '1' DAY;
Запрос 2 :
SELECT EMPLOYEE_ID,
TO_CHAR( TIME_IN, 'YYYY-MM-DD HH24:MI:SS.FF6 TZR' ) AS TIME_IN,
TO_CHAR( TIME_OUT, 'YYYY-MM-DD HH24:MI:SS.FF6 TZR' ) AS TIME_OUT,
WORKING_HOUR,
PUNCH_DATE,
TIME_OUT_HISTORY
FROM EMPLOYEE_LOGIN_TIME;
Результаты
| EMPLOYEE_ID | TIME_IN | TIME_OUT | WORKING_HOUR | PUNCH_DATE | TIME_OUT_HISTORY |
|-------------|--------------------------------|--------------------------------|--------------|---------------------|------------------|
| 73584 | 2018-05-14 09:00:00.000000 PST | 2018-05-14 10:14:00.771000 PST | 01:14:00 | 2018-05-14 09:00:00 | (null) |