Вы находитесь на странице: 1из 7

DECLARE

CURSOR C1 IS
select sumry."NUMBER" INC_NUM
,sumry.open_time
,sumry.priority_code
,sumry.severity
,sumry.status
,sumry.close_time
,sumry.logical_name
,sumry.actor
,sumry.incident_id
,sumry.resolved_by
,sumry.resolved_time
from hpsm_master.Probsummarym1 sumry
where sumry.assignment in ('APPS-SUPPORT-L2','APPS-SUPPORT-L3');
--AND ROWNUM<10;
-AND sumry."NUMBER" = 'IM300515';--'IM299202';--'IM254738';
l_ack_date
DATE := null;
L_response_time_hrs VARCHAR2(250) := null;
l_open_weekday
VARCHAR2(50) := NULL;
L_TOTAL_DIFF number := null;
l_pending1_Date date := null;
l_wip1_Date date := null;
l_pending2_Date date := null;
l_wip2_Date date := null;
l_customer_queue1 number := null;
l_customer_queue2 number := null;
l_resln_time varchar2(250) := null;
l_customer_queue number := null;
l_new_open_hrs
NUMBER := NULL;
l_new_open_time date := null;
l_new_open_min NUMBER := NULL;
BEGIN
FOR i IN C1 LOOP
l_ack_date
:= null;
L_response_time_hrs := null;
l_open_weekday
:= NULL;
L_TOTAL_DIFF := null;
l_pending1_Date := null;
l_wip1_Date := null;
l_pending2_Date := null;
l_wip2_Date := null;
l_customer_queue1 := null;
l_customer_queue2 := null;
l_resln_time := null;
l_customer_queue := null;
l_new_open_hrs := NULL;
l_new_open_time := null;
l_new_open_min := NULL;
BEGIN
SELECT DATESTAMP
INTO l_ack_date
FROM hpsm_master.Activitym1
WHERE TYPE = 'Status Change'
AND "NUMBER" = i.INC_NUM
AND DESCRIPTION LIKE '%Acknowledged from Referred%' ;
EXCEPTION
WHEN OTHERS THEN
l_ack_date := NULL;

--DBMS_OUTPUT'.PUT_LINE('Exception checking Ack from Ref:'||SQLERRM);


END;
IF l_ack_date IS NULL THEN
BEGIN
SELECT DATESTAMP
INTO l_ack_date
FROM hpsm_master.Activitym1
WHERE TYPE = 'Status Change'
AND "NUMBER" = i.inc_num
AND DESCRIPTION LIKE '%Acknowledged from Open%';
EXCEPTION
WHEN OTHERS THEN
l_ack_date := NULL;
--DBMS_OUTPUT'.PUT_LINE('Exception checking Ack from Ref:'||SQLERRM);
END;
END IF;
IF l_ack_date IS NULL THEN
BEGIN
SELECT DATESTAMP
INTO l_ack_date
FROM (
SELECT DATESTAMP
FROM hpsm_master.Activitym1
WHERE TYPE = 'Status Change'
AND "NUMBER" = i.inc_num
ORDER BY DATESTAMP ASC
)
WHERE ROWNUM=1;
EXCEPTION
WHEN OTHERS THEN
l_ack_date := NULL;
--DBMS_OUTPUT'.PUT_LINE('Exception checking Ack from Ref:'||SQLERRM);
END;
END IF;
--DBMS_OUTPUT'.PUT_LINE('l_ack_date:'||to_char(l_ack_date,'DD-MON-YYYY HH24:
MI:SS'));
--DBMS_OUTPUT'.PUT_LINE('open_time:'||to_char(I.open_time,'DD-MON-YYYY HH24:
MI:SS'));
/**********************Logic to derive new OPEN_DATE*********************/
l_new_open_hrs := to_number(to_char(i.open_time,'HH24'));
l_new_open_min := to_number(to_char(i.open_time,'MI'));
IF l_new_open_hrs < 8 THEN
--DBMS_OUTPUT'.PUT_LINE('<8');
l_new_open_time := to_date(TRUNC(i.open_time)||' 08:30:00','DD-MON-RRRR HH
24:MI:SS');
elsif l_new_open_hrs = 8 then
IF l_new_open_min < 30 THEN
l_new_open_time := to_date(TRUNC(i.open_time)||' 08:30:00','DD-MON-RRRR
HH24:MI:SS');
ELSE
l_new_open_time := i.open_time;
END IF;
ELSIF l_new_open_hrs > 17 THEN
l_new_open_time := to_date(TRUNC(i.open_time + 1)||' 08:30:00','DD-MON-RRR

R HH24:MI:SS');
ELSIF l_new_open_hrs = 17 THEN
IF l_new_open_min > 30 THEN
l_new_open_time := to_date(TRUNC(i.open_time + 1)||' 08:30:00','DD-MON-R
RRR HH24:MI:SS');
ELSE
l_new_open_time := i.open_time;
END IF;
ELSE
--DBMS_OUTPUT'.PUT_LINE('>8');
l_new_open_time := i.open_time;
END IF;
--DBMS_OUTPUT'.PUT_LINE('l_new_open_hrs:'||l_new_open_hrs);
--DBMS_OUTPUT'.PUT_LINE('l_new_open_time:'||TO_CHAR(l_new_open_time,'DD-MONRRRR HH24:MI:SS'));
/**********************Logic to derive new OPEN_DATE*********************/
if l_ack_date < l_new_open_time then
--DBMS_OUTPUT'.PUT_LINE('l_ack_date < l_new_open_time');
l_ack_date := l_new_open_time;
end if;
IF l_ack_date IS NOT NULL THEN
--DBMS_OUTPUT'.PUT_LINE('l_ack_date2:'||l_ack_date);
--DBMS_OUTPUT'.PUT_LINE('l_new_open_time2:'||l_new_open_time);
/* select round(24 * (to_date(l_ack_date, 'DD-MON-YYYY HH24:MI:SS')
- to_date(I.open_time, 'DD-MON-YYYY HH24:MI:SS')),2)
INTO L_response_time_hrs
from dual;
*/
SELECT floor(((l_ack_date-l_new_open_time)*24*60*60)/3600)
|| ' HOURS ' ||
floor((((l_ack_date-l_new_open_time)*24*60*60) floor(((l_ack_date-l_new_open_time)*24*60*60)/3600)*3600)/60)
|| ' MINUTES ' ||
round((((l_ack_date-l_new_open_time)*24*60*60) floor(((l_ack_date-l_new_open_time)*24*60*60)/3600)*3600 (floor((((l_ack_date-l_new_open_time)*24*60*60) floor(((l_ack_date-l_new_open_time)*24*60*60)/3600)*3600)/60)*60) ))
|| ' SECS '
INTO L_response_time_hrs
FROM DUAL;
else
SELECT floor(((i.resolved_time-l_new_open_time)*24*60*60)/3600)
|| ' HOURS ' ||
floor((((i.resolved_time-l_new_open_time)*24*60*60) floor(((i.resolved_time-l_new_open_time)*24*60*60)/3600)*3600)/60)
|| ' MINUTES ' ||
round((((i.resolved_time-l_new_open_time)*24*60*60) floor(((i.resolved_time-l_new_open_time)*24*60*60)/3600)*3600 (floor((((i.resolved_time-l_new_open_time)*24*60*60) floor(((i.resolved_time-l_new_open_time)*24*60*60)/3600)*3600)/60)*60
) ))
|| ' SECS '
INTO L_response_time_hrs
FROM DUAL;
END IF;
--DBMS_OUTPUT'.PUT_LINE('L_response_time_hrs:'||L_response_time_hrs);
SELECT to_char(l_new_open_time, 'DAY')
into l_open_weekday
FROM DUAL;

IF i.status = 'closed' and l_ack_date is not null then


l_total_diff := i.resolved_time - l_ack_date; ----------------------3
--DBMS_OUTPUT'.PUT_LINE('l_total_diff:'||l_total_diff);
--Check first pending
BEGIN
SELECT DATESTAMP
INTO l_pending1_Date
FROM (
SELECT DATESTAMP
FROM hpsm_master.Activitym1
WHERE description like '%to Pending%'
AND "NUMBER" = i.inc_num
ORDER BY DATESTAMP ASC
)
WHERE ROWNUM=1;
EXCEPTION
WHEN OTHERS THEN
l_pending1_Date := NULL;
--DBMS_OUTPUT'.PUT_LINE('Exception checking Ack from Ref:'||SQLERR
M);
END;
--Check first wip
BEGIN
SELECT DATESTAMP
INTO l_wip1_Date
FROM (
SELECT DATESTAMP
FROM hpsm_master.Activitym1
WHERE description like '%Work In Progress%'
AND "NUMBER" = i.inc_num
ORDER BY DATESTAMP ASC
)
WHERE ROWNUM=1;
EXCEPTION
WHEN OTHERS THEN
l_wip1_Date := NULL;
--DBMS_OUTPUT'.PUT_LINE('Exception checking Ack from Ref:'||SQLERR
M);
END;
--DBMS_OUTPUT'.PUT_LINE('l_pending1_Date:'||l_pending1_Date);
--DBMS_OUTPUT'.PUT_LINE('l_wip1_Date:'||l_wip1_Date);
if (l_pending1_Date is not null and l_wip1_Date is not null) then
if l_wip1_Date > l_pending1_Date then
l_customer_queue1 := l_wip1_Date - l_pending1_Date;----------------------1
else
l_customer_queue1 := 0;
end if;
elsif l_pending1_Date is not null and l_wip1_Date is null then
l_customer_queue1 := i.resolved_time - l_pending1_Date;
elsif l_pending1_Date is null and l_wip1_Date is null then
l_customer_queue1 := 0;
ELSIF l_pending1_date is null then

l_customer_queue1 := 0;
end if;
--DBMS_OUTPUT'.PUT_LINE('l_customer_queue1:'||l_customer_queue1);
--Check second pending
BEGIN
SELECT DATESTAMP
INTO l_pending2_Date
FROM (
SELECT DATESTAMP
FROM hpsm_master.Activitym1
WHERE description like '%to Pending%'
AND "NUMBER" = i.INC_NUM
ORDER BY DATESTAMP DESC
)
WHERE ROWNUM=1;
EXCEPTION
WHEN OTHERS THEN
l_pending2_Date := NULL;
--DBMS_OUTPUT'.PUT_LINE('Exception checking Ack from Ref:'||SQLERR
M);
END;
if l_pending2_Date > l_pending1_Date then
--Check second wip
BEGIN
SELECT DATESTAMP
INTO l_wip2_Date
FROM (
SELECT DATESTAMP
FROM hpsm_master.Activitym1
WHERE description like '%Work In Progress%'
AND "NUMBER" = i.inc_num
ORDER BY DATESTAMP ASC
)
WHERE ROWNUM=2;
EXCEPTION
WHEN OTHERS THEN
l_wip2_Date := NULL;
--DBMS_OUTPUT'.PUT_LINE('Exception checking Ack from Ref:'||SQLE
RRM);
END;
--DBMS_OUTPUT'.PUT_LINE('l_pending2_Date:'||l_pending2_Date);
--DBMS_OUTPUT'.PUT_LINE('l_wip2_Date:'||l_wip2_Date);
if l_pending2_Date > l_wip1_Date then
if (l_pending2_Date is not null and l_wip2_Date is not null) then
if l_wip2_Date > l_pending2_Date then
l_customer_queue2 := l_wip2_Date - l_pending2_Date;----------------------2
else
l_customer_queue2 := 0;
end if;
elsif l_pending2_Date is not null and l_wip2_Date is null AND l_cu
stomer_queue1 <> 0 then
l_customer_queue2 := i.resolved_time - l_pending2_Date;
elsif l_pending2_Date is null and l_wip2_Date is null then
l_customer_queue2 := 0;

ELSE
l_customer_queue2 := 0;
end if;
end if;
--DBMS_OUTPUT'.PUT_LINE('l_customer_queue2:'||l_customer_queue2);
else
l_customer_queue2 := 0;
end if;
IF (l_pending1_Date is not null and l_customer_queue1 = 0 AND l_cust
omer_queue2 = 0) THEN
l_customer_queue := i.resolved_time - l_pending1_Date;
else
l_customer_queue := l_customer_queue1 + l_customer_queue2;
END IF;
--DBMS_OUTPUT'.PUT_LINE('l_total_diff:'||l_total_diff);
--DBMS_OUTPUT'.PUT_LINE('l_customer_queue:'||l_customer_queue);
l_resln_time := floor(ABS(((l_total_diff - (l_customer_queue))*24*60
*60)/3600))
|| ' HOURS ' ||
floor((((l_total_diff - (l_customer_queue))*24*60*60) floor(((l_total_diff - (l_customer_queue))*24*60*60)/3600)*3600)
/60)
|| ' MINUTES ' ||
round((((l_total_diff - (l_customer_queue))*24*60*60) floor(((l_total_diff - (l_customer_queue))*24*60*60)/3600)*3600
(floor((((l_total_diff - (l_customer_queue))*24*60*60) floor(((l_total_diff - (l_customer_queue))*24*60*60)/3600)*3600
)/60)*60) ))
|| ' SECS ' ;
else
l_resln_time := L_response_time_hrs;
end if;
INSERT INTO XXKCI_SLA (INCIDENT_NUMBER
,OPEN_TIME
,OPEN_DAY
--DERIVE
,priority_code
,SEVERITY
,STATUS
,close_time
,logical_name
,actor
,incident_id
,resolved_by
,ack_date
--derive
,response_time
--derive
,RESOLVED_TIME
,resolution_time
)
values(i.inc_num,l_new_open_time,l_open_weekday,I.priority_code,I.SEVERITY
,I.STATUS,I.close_time,I.logical_name,
I.actor,I.incident_id,I.resolved_by,l_ack_date,L_response_time_hrs,
I.RESOLVED_TIME,l_resln_time);
END LOOP;

COMMIT;
EXCEPTION
WHEN OTHERS THEN
NULL;
--DBMS_OUTPUT'.PUT_LINE('Exception:'||SQLERRM);
END;

Вам также может понравиться