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

select

nvl(toms.source_system, rbm.source_system) source_system,


nvl(toms.package_name, rbm.package_name) package_name,
nvl(toms.product_name, rbm.product_name) product_name,
CASE WHEN toms.slo_status = 7021759771013444981 /* Active */
THEN 'Active'
WHEN toms.slo_status = 9140545748713273967 /* Discontinued */
THEN 'Discontinued'
ELSE 'Unknown'
END slo_status,
nvl(toms.billing_product_name, rbm.billing_product_name) billing_product_name,
nvl(toms.billing_product_ref, rbm.billing_product_ref) billing_product_ref,
nvl(toms.wholesale_price_plan_name, rbm.wholesale_price_plan_name)
wholesale_price_plan_name,
nvl(toms.wholesale_price_plan_ref, rbm.wholesale_price_plan_ref)
wholesale_price_plan_ref,
nvl(toms.event_type_name, rbm.event_type_name) event_type_name,
nvl(toms.event_type_ref, rbm.event_type_ref) event_type_ref,
nvl(toms.wholesale_rate_plan_name, rbm.wholesale_rate_plan_name)
wholesale_rate_plan_name,
nvl(toms.wholesale_rate_plan_ref, rbm.wholesale_rate_plan_ref)
wholesale_rate_plan_ref
from
(select billings.package_name,
CASE WHEN billings.product_name is null then (select value
from nc_params p
where p.object_id = billings.billing
and p.attr_id = 9144999386013786055 /* Billing Product Name */
) else billings.product_name end product_name,
billings.slo_status,
(select value
from nc_params p
where p.object_id = billings.billing
and p.attr_id = 9144999386013786055 /* Billing Product Name */
) billing_product_name,
(select value
from nc_params p
where p.object_id = billings.billing
and p.attr_id = 9144999386013786048 /* Billing Product Ref */
) billing_product_ref,
(select value
from nc_params p
where p.object_id = billings.billing
and p.attr_id = 9144999386013786057 /* Wholesale Price Plan Name */
) wholesale_price_plan_name,
(select value
from nc_params p
where p.object_id = billings.billing
and p.attr_id = 9144999386013786053 /* Wholesale Price Plan Ref */
) wholesale_price_plan_ref,
(select value
from nc_params p
where p.object_id = rate_plans.object_id
and p.attr_id = 9145000367513787891 /* Event Type Name */
) event_type_name,
(select value
from nc_params p
where p.object_id = rate_plans.object_id
and p.attr_id = 9145000367513787877 /* Event Type Ref */
) event_type_ref,
(select value
from nc_params p
where p.object_id = rate_plans.object_id
and p.attr_id = 9145000367513787893 /* Wholesale Rate Plan Name */
) wholesale_rate_plan_name,
(select value
from nc_params p
where p.object_id = rate_plans.object_id
and p.attr_id = 9145000367513787881 /* Wholesale Rate Plan Ref */
) wholesale_rate_plan_ref,
'ABSENT IN RB, PRESENTED IN TOMS' source_system
from
(select nvl(products.tlo_id, packages.tlo_id) tlo_id,
nvl(products.package_name, packages.package_name) package_name,
nvl(products.slo_id, packages.slo_id) slo_id,
nvl(products.product_name, packages.product_name) product_name,
nvl(products.billing, packages.billing) billing,
products.list_value_id slo_status
from
(select top_name.object_id tlo_id,
top_name.name package_name,
-- top_name.description package_desc,
sec_name.object_id slo_id,
sec_name.name product_name,
-- sec_name.description product_desc,
bill_prod_inv.object_id billing,
status.list_value_id
from nc_objects relation,
nc_references top,
nc_references sec,
nc_objects top_name,
nc_objects sec_name,
nc_objects pr_sch,
nc_references wps,
nc_objects wps_vers,
nc_objects bill_prod_inv,
nc_params status
where relation.object_type_id = 9125737315713245977 /* Parent Offering
to Child Offering Relationship */
and top.object_id = relation.object_id
and top.attr_id = 9125718672413237377 /* Parent */
and sec.object_id = relation.object_id
and sec.attr_id = 9125718672413237378 /* Child */
and top_name.object_id = top.reference
and sec_name.object_id = sec.reference
and top_name.object_id = pr_sch.parent_id (+)
and pr_sch.object_type_id (+) = 9144990800013774547 /* Pricing Scheme
*/
and pr_sch.object_id = wps.object_id (+)
and wps.attr_id (+) = 9145000367513787846 /* WPS */
and wps.reference = wps_vers.parent_id (+)
and wps_vers.object_type_id (+) = 9144990800013774562 /* WPS Version */
and wps_vers.object_id = bill_prod_inv.parent_id (+)
and bill_prod_inv.object_type_id (+) = 9144990800013774567 /* Billing Product
Involvement */
and bill_prod_inv.name (+) = sec_name.name
and sec_name.object_id = status.object_id (+)
and status.attr_id (+) = 7021759771013444983
) products
full outer join
(select distinct top_name.object_id tlo_id,
top_name.name package_name,
null slo_id,
null product_name,
bill_prod_inv.object_id billing
from nc_objects relation,
nc_references top,
nc_objects top_name,
nc_objects pr_sch,
nc_references wps,
nc_objects wps_vers,
nc_objects bill_prod_inv
where relation.object_type_id = 9125737315713245977 /* Parent Offering
to Child Offering Relationship */
and top.object_id = relation.object_id
and top.attr_id = 9125718672413237377 /* Parent */
and top_name.object_id = top.reference
and top_name.object_id = pr_sch.parent_id (+)
and pr_sch.object_type_id (+) = 9144990800013774547 /* Pricing Scheme
*/
and pr_sch.object_id = wps.object_id (+)
and wps.attr_id (+) = 9145000367513787846 /* WPS */
and wps.reference = wps_vers.parent_id (+)
and wps_vers.object_type_id (+) = 9144990800013774562 /* WPS Version */
and wps_vers.object_id = bill_prod_inv.parent_id (+)
and bill_prod_inv.object_type_id (+) = 9144990800013774567 /* Billing Product
Involvement */
) packages
on products.tlo_id = packages.tlo_id
and products.billing = packages.billing
) billings,
nc_objects rate_plans
where billings.billing = rate_plans.parent_id (+)
and rate_plans.object_type_id (+) = 9144990800013774574 /* Wholesale Rate Plan
Involvement */
and billings.package_name not in ('Historical Package')
) toms
full outer join
(SELECT
NVL(LEGACY.SOURCE_SYSTEM, GENESIS.SOURCE_SYSTEM) SOURCE_SYSTEM,
NVL(LEGACY.PACKAGE_NAME, GENESIS.TARIFF_DESC) PACKAGE_NAME,
NVL(LEGACY.PRODUCT_NAME, GENESIS.PRODUCT_NAME) PRODUCT_NAME,
GENESIS.PRODUCT_NAME billing_product_name,
GENESIS.PRODUCT_ID billing_product_ref,
GENESIS.TARIFF_NAME wholesale_price_plan_name,
GENESIS.TARIFF_ID wholesale_price_plan_ref,
GENESIS.event_type_name,
GENESIS.event_type_ref,
GENESIS.wholesale_rate_plan_name,
GENESIS.wholesale_rate_plan_ref,
NVL(GENESIS.product_family_id, LEGACY.product_family_id) product_family_id,
NVL(GENESIS.catalogue_change_id, LEGACY.catalogue_change_id)
catalogue_change_id,
GENESIS.rating_catalogue_id
FROM
(/*Legacy Start*/
SELECT
DISTINCT
'ABSENT IN TOMS, PRESENT IN RB' SOURCE_SYSTEM,
CASE
WHEN prod.product_name like '% %' and prod.product_family_id in (5, 6)
THEN 'M2M Services'
WHEN prod.product_name like '% %' and prod.product_family_id not in (5, 6)
THEN 'MVNO Services'
ELSE prod.product_name
END product_name,
CASE
WHEN prod.product_family_id in (5, 6)
THEN 52
ELSE 51
END product_family_id,
MAX(pack.catalogue_change_id) catalogue_change_id,
tariff.tariff_name,
pack.package_name
FROM
package pack,
packagehasproduct php,
product prod,
tariffelement tarel,
tariff tariff
where
--joins for package and product
pack.catalogue_change_id = php.catalogue_change_id
and pack.package_id = php.package_id
and php.product_id = prod.product_id
--joins from above to tariff element
and tarel.catalogue_change_id = pack.catalogue_change_id
and tarel.product_id = prod.product_id
--tariff element and tarif joins
and tarel.tariff_id = tariff.tariff_id
and php.packaged_tariff_id = tariff.tariff_id
/***************************************/
--clarification join one
and prod.product_id not in
( SELECT PRODUCT_ID
FROM PRODUCTHASPARENTPRODUCT
WHERE PARENT_PRODUCT_ID IN
(SELECT DISTINCT PARENT_PRODUCT_ID
FROM PRODUCTHASPARENTPRODUCT
WHERE PARENT_PRODUCT_ID NOT IN -- need to have explanation of this part
(SELECT PRODUCT_ID FROM PRODUCTHASPARENTPRODUCT
)
)
)

--------------------------------------------------------------------------------REM
OVING PACKAGES
and pack.package_name not in (
'DemoForGenisis IN Safelink 2',
'IDT Subscriber Package',
'MVNA Aspider Subscriber Package',
'MVNA Aspider Subscriber Package (PayGo)',
'MVNA Aspider Subscriber Package (USF)',
'MVNE Subscriber Package'
)
--gruoping to get max catalouge change id
GROUP BY
CASE
WHEN prod.product_name like '% %' and prod.product_family_id in (5, 6)
THEN 'M2M Services'
WHEN prod.product_name like '% %' and prod.product_family_id not in (5, 6)
THEN 'MVNO Services'
ELSE prod.product_name
END,
CASE
WHEN prod.product_family_id in (5, 6)
THEN 52
ELSE 51
END,
tariff.tariff_name,
pack.package_name) LEGACY
left join
(SELECT
'GENESIS ONLY' SOURCE_SYSTEM,
genesis.product_name,
genesis.product_id,
tariff.tariff_name,
tariff.tariff_desc,
tariff.tariff_id,
genesis.product_family_id,
MAX(tarel.catalogue_change_id) catalogue_change_id,
et.event_type_name event_type_name,
et.event_type_id event_type_ref,
rating.tariff_name wholesale_rate_plan_name,
rating.rating_tariff_id wholesale_rate_plan_ref,
MAX(rating.rating_catalogue_id) rating_catalogue_id
FROM
product genesis,
tariffelement tarel,
tariff tariff,
tariffhasratingtariff thrt,
ratingtariff rating,
ratingtarifftype rtt,
tariffeventbind teb,
eventtype et,
producthaseventtype phet
WHERE
genesis.product_id >= 1500
and genesis.product_id = tarel.product_id (+)
and tarel.tariff_id = tariff.tariff_id (+)
and tarel.catalogue_change_id = tariff.catalogue_change_id (+)
and tariff.tariff_id = thrt.tariff_id (+)
and tariff.catalogue_change_id = thrt.catalogue_change_id (+)
and thrt.rating_tariff_id = rating.rating_tariff_id (+)
--and rating.rating_catalogue_id (+) = 290
and rating.rating_tariff_type_id = rtt.rating_tariff_type_id (+)
and rating.rating_catalogue_id = rtt.rating_catalogue_id (+)
and rtt.rating_tariff_type_id = teb.rating_tariff_type_id (+)
and rtt.rating_catalogue_id = teb.rating_catalogue_id (+)
and teb.event_type_id = et.event_type_id (+)
and et.event_type_id = phet.event_type_id (+)
and tariff.tariff_id = phet.product_id (+)
GROUP BY
genesis.product_name,
genesis.product_id,
tariff.tariff_name,
tariff.tariff_desc,
tariff.tariff_id,
genesis.product_family_id,
et.event_type_name,
et.event_type_id,
rating.tariff_name,
rating.rating_tariff_id) GENESIS
ON
LEGACY.product_name = GENESIS.product_name
AND LEGACY.product_family_id = GENESIS.product_family_id
AND GENESIS.tariff_name = case
when genesis.product_id in (1501, 1509)
then LEGACY.tariff_name
when genesis.product_id = 1510
then '250 Free SMS'
when genesis.product_id = 1511
then '1000 Free SMS'
when genesis.product_id = 1512
then 'Free Unlimited SMS'
when genesis.product_id = 1513
then '400 Free SMS'
when genesis.product_id = 1516
then '100 Free SMS'
when genesis.product_id = 1517
then '30 Free SMS'
when genesis.product_id = 1525
then 'Simple EMPL'
when genesis.product_id = 1526
then 'Simple MULTILINE'
-- TF
when genesis.product_id = 1505
and upper(legacy.package_name) like 'TR%'
then 'Tracfone THRWS31'
when genesis.product_id = 1506
and upper(legacy.package_name) like 'TR%'
then 'Tracfone THRWS32'
when genesis.product_id = 1507
and upper(legacy.package_name) like 'TR%'
then 'Tracfone THRWS33'
when genesis.product_id = 1508
and upper(legacy.package_name) like 'TR%'
then 'Tracfone WADADJTH4'
when genesis.product_id = 1518
and upper(legacy.package_name) like 'TR%'
then 'Tracfone WADADJTH5'
when genesis.product_id = 1519
and upper(legacy.package_name) like 'TR%'
then 'Tracfone WDRADJBLK'
when genesis.product_id = 1520
and upper(legacy.package_name) like 'TR%'
then 'Tracfone WHIADJTHR2'
when genesis.product_id = 1521
and upper(legacy.package_name) like 'TR%'
then 'Tracfone WHIADJTHR1'
when genesis.product_id = 1522
and upper(legacy.package_name) like 'TR%'
then 'Tracfone WHOADJTH2'
when genesis.product_id = 1523
and upper(legacy.package_name) like 'TR%'
then 'Tracfone WIRADJBLK'
-- SMPL
when genesis.product_id = 1505
and upper(legacy.package_name) like 'SIMPLE%'
then 'Simple THRWS31'
when genesis.product_id = 1506
and upper(legacy.package_name) like 'SIMPLE%'
then 'Simple THRWS32'
when genesis.product_id = 1507
and upper(legacy.package_name) like 'SIMPLE%'
then 'Simple THRWS33'
when genesis.product_id = 1508
and upper(legacy.package_name) like 'SIMPLE%'
then 'Simple WADADJTH4'
when genesis.product_id = 1518
and upper(legacy.package_name) like 'SIMPLE%'
then 'Simple WADADJTH5'
when genesis.product_id = 1519
and upper(legacy.package_name) like 'SIMPLE%'
then 'Simple WDRADJBLK'
when genesis.product_id = 1520
and upper(legacy.package_name) like 'SIMPLE%'
then 'Simple WHIADJTHR2'
when genesis.product_id = 1521
and upper(legacy.package_name) like 'SIMPLE%'
then 'Simple WHIADJTHR1'
when genesis.product_id = 1522
and upper(legacy.package_name) like 'SIMPLE%'
then 'Simple WHOADJTH2'
when genesis.product_id = 1523
and upper(legacy.package_name) like 'SIMPLE%'
then 'Simple WIRADJBLK'
when genesis.product_id in (1527, 1528, 1529, 1530)
then 'M2M '||genesis.product_name
end
AND GENESIS.tariff_desc = case
when genesis.product_id in (1501, 1509)
then LEGACY.package_name
when genesis.product_id = 1510
then '250 Free SMS'
when genesis.product_id = 1511
then '1000 Free SMS'
when genesis.product_id = 1512
then 'Free Unlimited SMS'
when genesis.product_id = 1513
then '400 Free SMS'
when genesis.product_id = 1516
then '100 Free SMS'
when genesis.product_id = 1517
then '30 Free SMS'
when genesis.product_id = 1525
then 'Simple EMPL'
when genesis.product_id = 1526
then 'Simple MULTILINE'
-- TF
when genesis.product_id = 1505
and upper(legacy.package_name) like 'TR%'
then 'Tracfone THRWS31'
when genesis.product_id = 1506
and upper(legacy.package_name) like 'TR%'
then 'Tracfone THRWS32'
when genesis.product_id = 1507
and upper(legacy.package_name) like 'TR%'
then 'Tracfone THRWS33'
when genesis.product_id = 1508
and upper(legacy.package_name) like 'TR%'
then 'Tracfone WADADJTH4'
when genesis.product_id = 1518
and upper(legacy.package_name) like 'TR%'
then 'Tracfone WADADJTH5'
when genesis.product_id = 1519
and upper(legacy.package_name) like 'TR%'
then 'Tracfone WDRADJBLK'
when genesis.product_id = 1520
and upper(legacy.package_name) like 'TR%'
then 'Tracfone WHIADJTHR2'
when genesis.product_id = 1521
and upper(legacy.package_name) like 'TR%'
then 'Tracfone WHIADJTHR1'
when genesis.product_id = 1522
and upper(legacy.package_name) like 'TR%'
then 'Tracfone WHOADJTH2'
when genesis.product_id = 1523
and upper(legacy.package_name) like 'TR%'
then 'Tracfone WIRADJBLK'
-- SMPL
when genesis.product_id = 1505
and upper(legacy.package_name) like 'SIMPLE%'
then 'Simple THRWS31'
when genesis.product_id = 1506
and upper(legacy.package_name) like 'SIMPLE%'
then 'Simple THRWS32'
when genesis.product_id = 1507
and upper(legacy.package_name) like 'SIMPLE%'
then 'Simple THRWS33'
when genesis.product_id = 1508
and upper(legacy.package_name) like 'SIMPLE%'
then 'Simple WADADJTH4'
when genesis.product_id = 1518
and upper(legacy.package_name) like 'SIMPLE%'
then 'Simple WADADJTH5'
when genesis.product_id = 1519
and upper(legacy.package_name) like 'SIMPLE%'
then 'Simple WDRADJBLK'
when genesis.product_id = 1520
and upper(legacy.package_name) like 'SIMPLE%'
then 'Simple WHIADJTHR2'
when genesis.product_id = 1521
and upper(legacy.package_name) like 'SIMPLE%'
then 'Simple WHIADJTHR1'
when genesis.product_id = 1522
and upper(legacy.package_name) like 'SIMPLE%'
then 'Simple WHOADJTH2'
when genesis.product_id = 1523
and upper(legacy.package_name) like 'SIMPLE%'
then 'Simple WIRADJBLK'
when genesis.product_id in (1527, 1528, 1529, 1530)
then 'M2M '||genesis.product_name
end
--ORDER BY PACKAGE_NAME, PRODUCT_NAME DESC
) rbm
on nvl(toms.package_name, 'null') = nvl(rbm.package_name, 'null')
and nvl(toms.product_name, 'null') = nvl(rbm.product_name, 'null')
and nvl(toms.billing_product_name, 'null') = nvl(rbm.billing_product_name,
'null')
and nvl(toms.billing_product_ref, 1) = nvl(rbm.billing_product_ref, 1)
and nvl(toms.wholesale_price_plan_name, 'null') =
nvl(rbm.wholesale_price_plan_name, 'null')
and nvl(toms.wholesale_price_plan_ref, 1) = nvl(rbm.wholesale_price_plan_ref,
1)
and nvl(toms.event_type_name, 'null') = nvl(rbm.event_type_name, 'null')
and nvl(toms.event_type_ref, 1) = nvl(rbm.event_type_ref, 1)
and nvl(toms.wholesale_rate_plan_name, 'null') = nvl(rbm.wholesale_rate_plan_name,
'null')
and nvl(toms.wholesale_rate_plan_ref, 1) = nvl(rbm.wholesale_rate_plan_ref,
1)
where
(toms.package_name is null
or rbm.package_name is null)
--toms.package_name = 'Cintex Subscriber Package1'
--or rbm.package_name = 'Cintex Subscriber Package1'
order by package_name, product_name

Оценить