SELECT org.organization_code organization_code,
crd.resources resources,
crm.resource_desc resource_description,
TO_CHAR(grum.from_date, 'DD-MON-YYYY HH24:MI:SS') start_time,
TO_CHAR(grum.to_date, 'DD-MON-YYYY HH24:MI:SS') stop_time,
floor(((grum.to_date-grum.from_date)*24*60*60)/3600) || ':' || ROUND((((grum.to_date-grum.from_date)*24*60*60) - floor(((grum.to_date-grum .from_date)*24*60*60)/3600)*3600)/60) || ':' || ROUND((((grum.to_date-grum.from_date) *24*60*60) - floor(((grum.to_date-grum .from_date)*24*60*60)/3600)*3600 - (ROUND((((grum.to_date- grum.from_date)*24*60* 60) - floor(((grum.to_date-grum.from_date)*24*60*60)/3600)*3600)/60)*60) ))
elapsed_time,
grum.reason_code reason_code,
mtr.description reason_description
FROM org_organization_definitions org,
cr_rsrc_dtl crd,
CR_RSRC_MST crm,
gmp_rsrc_unavail_man grum,
MTL_TRANSACTION_REASONS mtr
WHERE org.organization_id = crd.organization_id
--AND org.organization_code = NVL(:ORG_CODE,org.organization_code)
AND crd.resource_id = grum.resource_id
AND crd.resources = crm.resources
--AND crd.resources = NVL(:RESOURCES,crd.resources)
AND grum.reason_code = mtr.reason_name(+)
--AND grum.reason_code = NVL(:REASON_CODE,grum.reason_code)
AND (TO_CHAR(grum.from_date,'YYYY/MM/DD') >= '2012/02/22'
AND TO_CHAR(grum.to_date,'YYYY/MM/DD') <= '2012/02/22')
-- and (grum.to_date >= '0-jan-12' and grum.to_date <'04-jan-12')
-- AND to_char(nvl(grum.from_date,SYSDATE),'YYYY/MM/DD HH24:MI:SS') between nv l (:START_FROM_DATE,to_char(nvl(grum.from_date,SYSDATE),'YYYY/MM/DD HH24:MI:SS'))
AND nvl(:START_TO_DATE,to_char(nvl(grum.from_date,SYSDATE),'YYYY/MM/DD HH24:MI: SS'))
-- AND to_char(nvl(grum.to_date,SYSDATE),'YYYY/MM/DD HH24:MI:SS')
between nvl (:STOP_FROM_DATE,to_char(nvl(grum.to_date,SYSDATE),'YYYY/MM/DD HH24:MI:SS'))
AND nvl(:STOP_TO_DATE,to_char(nvl(grum.to_date,SYSDATE),'YYYY/MM/DD HH24:MI:SS'))
ORDER BY org.organization_code, crd.resources, grum.from_date
crd.resources resources,
crm.resource_desc resource_description,
TO_CHAR(grum.from_date, 'DD-MON-YYYY HH24:MI:SS') start_time,
TO_CHAR(grum.to_date, 'DD-MON-YYYY HH24:MI:SS') stop_time,
floor(((grum.to_date-grum.from_date)*24*60*60)/3600) || ':' || ROUND((((grum.to_date-grum.from_date)*24*60*60) - floor(((grum.to_date-grum .from_date)*24*60*60)/3600)*3600)/60) || ':' || ROUND((((grum.to_date-grum.from_date) *24*60*60) - floor(((grum.to_date-grum .from_date)*24*60*60)/3600)*3600 - (ROUND((((grum.to_date- grum.from_date)*24*60* 60) - floor(((grum.to_date-grum.from_date)*24*60*60)/3600)*3600)/60)*60) ))
elapsed_time,
grum.reason_code reason_code,
mtr.description reason_description
FROM org_organization_definitions org,
cr_rsrc_dtl crd,
CR_RSRC_MST crm,
gmp_rsrc_unavail_man grum,
MTL_TRANSACTION_REASONS mtr
WHERE org.organization_id = crd.organization_id
--AND org.organization_code = NVL(:ORG_CODE,org.organization_code)
AND crd.resource_id = grum.resource_id
AND crd.resources = crm.resources
--AND crd.resources = NVL(:RESOURCES,crd.resources)
AND grum.reason_code = mtr.reason_name(+)
--AND grum.reason_code = NVL(:REASON_CODE,grum.reason_code)
AND (TO_CHAR(grum.from_date,'YYYY/MM/DD') >= '2012/02/22'
AND TO_CHAR(grum.to_date,'YYYY/MM/DD') <= '2012/02/22')
-- and (grum.to_date >= '0-jan-12' and grum.to_date <'04-jan-12')
-- AND to_char(nvl(grum.from_date,SYSDATE),'YYYY/MM/DD HH24:MI:SS') between nv l (:START_FROM_DATE,to_char(nvl(grum.from_date,SYSDATE),'YYYY/MM/DD HH24:MI:SS'))
AND nvl(:START_TO_DATE,to_char(nvl(grum.from_date,SYSDATE),'YYYY/MM/DD HH24:MI: SS'))
-- AND to_char(nvl(grum.to_date,SYSDATE),'YYYY/MM/DD HH24:MI:SS')
between nvl (:STOP_FROM_DATE,to_char(nvl(grum.to_date,SYSDATE),'YYYY/MM/DD HH24:MI:SS'))
AND nvl(:STOP_TO_DATE,to_char(nvl(grum.to_date,SYSDATE),'YYYY/MM/DD HH24:MI:SS'))
ORDER BY org.organization_code, crd.resources, grum.from_date