The following lines contain the word 'select', 'insert', 'update' or 'delete':
l_select_stmt VARCHAR2(10000);
l_inner_select_stmt VARCHAR2(10000);
(SELECT 1
FROM org_access o
WHERE o.responsibility_id = fnd_global.resp_id
AND o.resp_application_id = fnd_global.resp_appl_id
AND o.organization_id = fact.inv_org_id)
OR EXISTS
(SELECT 1
FROM mtl_parameters org
WHERE org.organization_id = fact.inv_org_id
AND NOT EXISTS
(SELECT 1
FROM org_access ora
WHERE org.organization_id = ora.organization_id)))';
THEN l_select_stmt := '
SELECT items.value VIEWBY,
NULL ISC_ATTRIBUTE_2,
NULL ISC_ATTRIBUTE_3, -- drill across url
items.description ISC_ATTRIBUTE_4, -- item description
'||l_measures||'
FROM
(SELECT (rank() over (&ORDER_BY_CLAUSE nulls last, item_id)) - 1 rnk,
item_id,
'||l_measures||'
FROM
(SELECT c.item_id,';
l_inner_select_stmt := '
SELECT fact.item_id ITEM_ID,';
THEN l_select_stmt := '
SELECT org.name VIEWBY,
NULL ISC_ATTRIBUTE_2,
NULL ISC_ATTRIBUTE_3, -- drill across url
NULL ISC_ATTRIBUTE_4, -- item description
'||l_measures||'
FROM
(SELECT (rank() over (&ORDER_BY_CLAUSE nulls last, inv_org_id)) - 1 rnk,
inv_org_id,
'||l_measures||'
FROM
(SELECT c.inv_org_id, ';
l_inner_select_stmt := '
SELECT fact.inv_org_id INV_ORG_ID,';
THEN l_select_stmt := '
SELECT cust.value VIEWBY,
NULL ISC_ATTRIBUTE_2,
NULL ISC_ATTRIBUTE_3, -- drill across url
NULL ISC_ATTRIBUTE_4, -- item description
'||l_measures||'
FROM
(SELECT (rank() over (&ORDER_BY_CLAUSE nulls last, customer_id)) - 1 rnk,
customer_id,
'||l_measures||'
FROM
(SELECT c.customer_id, ';
l_inner_select_stmt := '
SELECT fact.customer_id CUSTOMER_ID,';
l_select_stmt := '
SELECT ecat.value VIEWBY,
ecat.id VIEWBYID,
NULL ISC_ATTRIBUTE_2,
decode(ecat.leaf_node_flag, ''Y'',
''pFunctionName=ISC_DBI_DAYS_FULF&VIEW_BY_NAME=VIEW_BY_ID&VIEW_BY=ITEM+ENI_ITEM_ORG&pParamIds=Y'',
''pFunctionName=ISC_DBI_DAYS_FULF&VIEW_BY_NAME=VIEW_BY_ID&VIEW_BY=ITEM+ENI_ITEM_VBH_CAT&pParamIds=Y'')
ISC_ATTRIBUTE_3, -- drill across url
NULL ISC_ATTRIBUTE_4, -- item description
'||l_measures||'
FROM
(SELECT (rank() over (&ORDER_BY_CLAUSE nulls last, item_category_id)) - 1 rnk,
item_category_id,
'||l_measures||'
FROM
(SELECT c.item_category_id, ';
l_inner_select_stmt := '
SELECT eni_cat.parent_id ITEM_CATEGORY_ID,';
l_inner_select_stmt := '
SELECT eni_cat.imm_child_id ITEM_CATEGORY_ID,';
l_inner_select_stmt := '
SELECT fact.parent_id ITEM_CATEGORY_ID,';
l_inner_select_stmt := '
SELECT fact.imm_child_id ITEM_CATEGORY_ID,';
l_stmt := l_select_stmt || '
c.curr_fulf_days
/ decode(c.curr_fulf_cnt, 0, NULL,
c.curr_fulf_cnt) ISC_MEASURE_1, -- days fulf
c.curr_fulf_days
/ decode(c.curr_fulf_cnt, 0, NULL,
c.curr_fulf_cnt) -
c.prev_fulf_days
/ decode(c.prev_fulf_cnt, 0, NULL,
c.prev_fulf_cnt) ISC_MEASURE_2, -- days fulf change
sum(c.curr_fulf_days) over ()
/ decode(sum(c.curr_fulf_cnt) over (), 0, NULL,
sum(c.curr_fulf_cnt) over ()) ISC_MEASURE_3, -- gd total days fulf
sum(c.curr_fulf_days) over ()
/ decode(sum(c.curr_fulf_cnt) over (), 0, NULL,
sum(c.curr_fulf_cnt) over ()) -
sum(c.prev_fulf_days) over ()
/ decode(sum(c.prev_fulf_cnt) over (), 0, NULL,
sum(c.prev_fulf_cnt) over ()) ISC_MEASURE_4, -- gd total days fulf change
NULL ISC_MEASURE_5,
NULL ISC_MEASURE_6,
NULL ISC_MEASURE_7,
NULL ISC_MEASURE_8,
NULL CURRENCY, -- obsoleted from 5.0
NULL FND_CATEGORY, -- obsoleted from 5.0
NULL FND_PRODUCT -- obsoleted from 5.0
FROM ('||l_inner_select_stmt||'
sum(decode(cal.report_date, &BIS_CURRENT_ASOF_DATE,
fact.book_to_fulfill_days, 0)) CURR_FULF_DAYS,
sum(decode(cal.report_date, &BIS_PREVIOUS_ASOF_DATE,
fact.book_to_fulfill_days, 0)) PREV_FULF_DAYS,
sum(decode(cal.report_date, &BIS_CURRENT_ASOF_DATE,
fact.book_to_fulfill_cnt, 0)) CURR_FULF_CNT,
sum(decode(cal.report_date, &BIS_PREVIOUS_ASOF_DATE,
fact.book_to_fulfill_cnt, 0)) PREV_FULF_CNT
FROM '||l_mv||' fact,
FII_TIME_RPT_STRUCT_V cal'||l_prod_cat_from||'
WHERE fact.time_id = cal.time_id
AND fact.return_flag = 0'||l_flags_where||'
AND cal.report_date IN (&BIS_CURRENT_ASOF_DATE, &BIS_PREVIOUS_ASOF_DATE)
AND cal.period_type_id = fact.period_type_id
AND bitand(cal.record_type_id, &BIS_NESTED_PATTERN) = cal.record_type_id'
||l_inv_org_where
||l_prod_cat_where
||l_prod_where
||l_cust_where
||l_inner_group_by_stmt||') c)
WHERE ISC_MEASURE_1 IS NOT NULL
OR ISC_MEASURE_2 IS NOT NULL) a,'
||l_where_stmt;