I need your expert advice on the following requirement:-
I have two main tables namely HLR and BSS ,each contains unique "SUBSCRIBER_NO" , list of comma separated "Service ID's" and their comma separated "Service Status's ( A- Active , I - In Active)". These two tables can be joined on column "SUBSCRIBER_NO".
Table creation and population script is as follows:-
- Code: Select all
create table HLR(SUBSCRIBER_NO Number, Service_ID varchar2(100), Service_Status VARCHAR2(100));
insert into HLR (SUBSCRIBER_NO, SERVICE_ID, SERVICE_STATUS)
values (100001, '110,111', 'A,I');
insert into HLR (SUBSCRIBER_NO, SERVICE_ID, SERVICE_STATUS)
values (100002, '110,115', 'I,A');
insert into HLR (SUBSCRIBER_NO, SERVICE_ID, SERVICE_STATUS)
values (100003, '110,115', 'A,I');
create table BSS(Subscriber_No Number, Service_ID varchar2(100), Service_Status VARCHAR2(100));
insert into BSS (SUBSCRIBER_NO, SERVICE_ID, SERVICE_STATUS)
values (100001, '10,15', 'I,A');
insert into BSS (SUBSCRIBER_NO, SERVICE_ID, SERVICE_STATUS)
values (100002, '15,25', 'A,I');
insert into BSS (SUBSCRIBER_NO, SERVICE_ID, SERVICE_STATUS)
values (100003, '15,-1', 'A,I');
In addition to the above two tables, I have one mapping table "HLR_BSS_MAPPING" which contains the mapped "Service_ID" of these two sources(i.e. HLR & BSS). Creation /Population script is as follows:-
- Code: Select all
create table HLR_BSS_MAPPING(Group_ID Number, MAPPED_SERVICE_ID_SOURCES Number);
insert into hlr_bss_mapping (GROUP_ID, MAPPED_SERVICE_ID_SOURCES)
values (1, 110);
insert into hlr_bss_mapping (GROUP_ID, MAPPED_SERVICE_ID_SOURCES)
values (1, 15);
insert into hlr_bss_mapping (GROUP_ID, MAPPED_SERVICE_ID_SOURCES)
values (2, 111);
insert into hlr_bss_mapping (GROUP_ID, MAPPED_SERVICE_ID_SOURCES)
values (2, 10);
insert into hlr_bss_mapping (GROUP_ID, MAPPED_SERVICE_ID_SOURCES)
values (3, 115);
insert into hlr_bss_mapping (GROUP_ID, MAPPED_SERVICE_ID_SOURCES)
values (3, 25);
I have to look into this mapping table to decide which Service ID of "HLR" source is to be mapped with which Service ID of "BSS" source.
For example :- The Service ID "110" of source "HLR" (taken from first row value 110,111') will be matched with Service ID "15" of source "BSS" (taken from first row value 10,15') , as these two Service ID's have common Group_ID in "HLR_BSS_MAPPING" table( i.e. GROUP_ID 1).
I have to write a Query/Procedure(Preferably Query) which will produce a column "STATUS" which holds the following three status:-
1) Status "0" (Matched Services) : These services are those , whose Comma separated Service Status corresponding to the Comma Separated Service ID's are same in both HLR and BSS sources.
For example ,The SUBSCRIBER_NO "100001" should have the Matched Status as from the comma separated service ID's , service ID "110" (of HLR) & "15 " (of BSS) has the same Service Status as "A-Active" and also second Service ID in this i.e 111(HLR) and 10(BSS) has the same Service Status as "I-In Active".
2) Status "1" (Mis-Matched Services) : These services are those , whose Comma separated Service Status corresponding to the Comma Separated Service ID's are not same in both HLR and BSS sources.
For example ,The SUBSCRIBER_NO "100002" should have the Mis-Matched Status as the Service Status of Service ID's 110 & 15 are "A" and "I" which is not same , same applicable for Service ID's 115 & 25.
3) Status "2" (Missing Services): These services are those , whose Service ID is not mapped in "HLR_BSS_MAPPING" table i.e. Service ID not available in HLR_BSS_MAPPING table.For example The SUBSCRIBER_NO "100003" should have the Missing Status as the Service ID "-1" of source "BSS" is not available/mapped in "HLR_BSS_MAPPING" table.
Can you guide me to write a query /PL SQL for the above ,that query/procedure should
1) first join the HLR & BSS table based on "SUBSCRIBER_NO" column.
2) then find out the mapped service ID based on "GROUP_ID" column of HLR_BSS_MAPPING table.
3) then produces a third "STATUS" column based on the "SERVICE_STATUS" column value for the mapped Service_ID of the HLR and BSS sources.
I am stuck very badly and need your expert advice,please guide me.
Thanks in advance.
Thanks & Regards,
Anand Kumar Ojha