Vous êtes sur la page 1sur 4

Steps followed for converting the data: create table xxudc.xxrl_grosssales_pre_temp as select * from xxudc.

xxrl_grosssal es_temp where 1 = 2 ALTER TABLE xxudc.xxrl_grosssales_temp add CONSTRAINT xxrl_grosssales_cons UNIQUE (hot_number,month); ALTER TABLE XXUDC.xxrl_grosssales_temp MODIFY (HOT_NUMBER NOT NULL,BRAND_DAME no t null,MONTH not NULL,GROSS_SALES_AMOUNT NOT NULL); select hot_number,month,count(1) from xxudc.xxrl_grosssales_temp group by hot_number,month having count(1) > 1 select * from XXUDC.xxrl_grosssales_temp where hot_number = 'H2109' and month = '01-DEC-2010' select distinct y.document_number||' '||x.hot_header_id||' '|| to_char(x.start_date,'DD-MON-YYYY') from xxrl_gross_sales_t x, xxrl_head_of_terms_header_t y where hot_header_id = header_id AND y.revision_number=(SELECT MAX(revision_number) FROM xxrl_head_of_terms_header_t WHERE document_number=y.document_number) and document_number = 'H2109' and start_date = '01DEC-2010' select * from xxrl_gross_sales_t where hot_header_id = 577 and start_date = '01DEC-2010' --delete from xxrl_gross_sales_t where hot_header_id = 577 and start_date = '01 -DEC-2010' and gross_sales_amount = '68282' --delete from XXUDC.xxrl_grosssales_temp where hot_number = 'H2109' and month = '01-DEC-2010' and gross_sales_amount = '68282' ALTER TABLE xxudc.xxrl_grosssales_temp add rundate date; Load the data to the table. "xxudc.xxrl_grosssales_temp" -- Loaded 198 rows to this table. Find duplicates in the table and confirm. To extract the list of duplicates do as follows: ( SELECT distinct xhth.document_number hotnum,xhth.header_id headerid, to_char(b.month,'DD-MON-YYYY') mth FROM xxrl_head_of_terms_header_t xhth, xxudc.xxrl_grosssales_pre_temp b, xxrl_head_of_terms_details_v xhtdv WHERE xhth.document_number= b.hot_number AND xhth.revision_number=(SELECT MAX(revision_number) FROM xxrl_head_of_terms_header_t WHERE document_number=xhth.document_number) AND xhth.header_id=xhtdv.header_id AND xhtdv.charge_type='Rent'

AND TO_CHAR(xhtdv.effective_from_date,'YYYY')=TO_CHAR(b.month,'YYYY') AND nvl(b.validated_flag,'N') = 'N' INTERSECT select distinct y.document_number hotnum,x.hot_header_id headerid, to_char(x.start_date,'DD-MON-YYYY') mth from xxrl_gross_sales_t x, xxrl_head_of_terms_header_t y where hot_header_id = header_id AND y.revision_number=(SELECT MAX(revision_number) FROM xxrl_head_of_terms_header_t WHERE document_number=y.document_number) ) select (SELECT distinct xhth.header_id||' '||to_char(b.month,'DD-MON-YYYY') FROM xxrl_head_of_terms_header_t xhth, xxudc.xxrl_grosssales_pre_temp b, xxrl_head_of_terms_details_v xhtdv WHERE xhth.document_number= b.hot_number AND xhth.revision_number=(SELECT MAX(revision_number) FROM xxrl_head_of_terms_header_t WHERE document_number=xhth.document_number) AND xhth.header_id=xhtdv.header_id AND xhtdv.charge_type='Rent' AND TO_CHAR(xhtdv.effective_from_date,'YYYY')=TO_CHAR(b.month,'YYYY') AND nvl(b.validated_flag,'N') = 'N' INTERSECT select distinct x.hot_header_id||' '||to_char(x.start_date,'DD-MON-YYYY') from xxrl_gross_sales_t x, xxrl_head_of_terms_header_t y where hot_header_id = header_id AND y.revision_number=(SELECT MAX(revision_number) FROM xxrl_head_of_terms_header_t WHERE document_number=y.document_number) ) SELECT distinct xhth.document_number hotnum,xhth.header_id headerid, to_char(b.month,'DD-MON-YYYY') mth,b.gross_sales_amount FROM xxrl_head_of_terms_header_t xhth, xxudc.xxrl_grosssales_pre_temp b, xxrl_head_of_terms_details_v xhtdv, xxrl_gross_sales_t x WHERE xhth.document_number= b.hot_number AND xhth.revision_number=(SELECT MAX(revision_number) FROM xxrl_head_of_terms_header_t WHERE document_number=xhth.document_number) AND xhth.header_id=xhtdv.header_id AND xhtdv.charge_type='Rent' AND TO_CHAR(xhtdv.effective_from_date,'YYYY')=TO_CHAR(b.month,'YYYY') AND nvl(b.validated_flag,'N') = 'N' and x.hot_header_id = xhth.header_id and x.start_date = b.month To check up for duplicates -------------------------This is very important to check by DOCUMENT_NUMBER and START_DATE

select distinct document_number ,start_date from xxrl_gross_sales_t x, xxrl_head_of_terms_header_t y where hot_header_id = header_id AND y.revision_number=(SELECT MAX(revision_number) FROM xxrl_head_of_terms_header_t WHERE document_number=y.document_number) group by document_number ,start_date having count(1) > 1 Steps followed in SQL PLUS session: SQL> set serveroutput on size 1000000; SQL> select count(1) from xxrl_gross_sales_t; COUNT(1) --------1064 SQL> exec XXRL_GROSSSALESDTLS_NEW.XXRL_INSERT_GROSSSALES; begin Total gross sales records entered 170 Total gross sales records changed 28 Records with validated flag not updated is: PL/SQL procedure successfully completed. SQL> select count(1) from xxrl_gross_sales_t where trunc(creation_date) <> trunc (last_update_date) 2 and trunc(last_update_date) = trunc(sysdate); COUNT(1) --------28 SQL> select count(1) from xxrl_gross_sales_t where trunc(creation_date) = trun c(last_update_date) 2 and trunc(last_update_date) = trunc(sysdate); COUNT(1) --------170 SQL> select count(1) from xxudc.xxrl_grosssales_pre_temp where action_flag = 'I' ; COUNT(1) --------170 SQL> select count(1) from xxudc.xxrl_grosssales_pre_temp where action_flag = 'U' ; COUNT(1) --------28 SQL> select count(1) from xxudc.xxrl_grosssales_temp where action_flag = 'I'; COUNT(1) ---------

170 SQL> select count(1) from xxudc.xxrl_grosssales_temp where action_flag = 'U'; COUNT(1) --------28 SQL> commit; Commit complete. select distinct document_number ,hot_header_id headerid,start_date month,gross_s ales_amount from xxrl_gross_sales_t x, xxrl_head_of_terms_header_t y where hot_header_id = header_id AND y.revision_number=(SELECT MAX(revision_number) FROM xxrl_head_of_terms_header_t WHERE document_number=y.document_number) and trunc(x.creation_date) <> trunc(x.last_update_d ate) and trunc(x.last_update_date) = trunc(sysdate)

select distinct document_number ,hot_header_id headerid,start_date month,gross_s ales_amount from xxrl_gross_sales_t x, xxrl_head_of_terms_header_t y where hot_header_id = header_id AND y.revision_number=(SELECT MAX(revision_number) FROM xxrl_head_of_terms_header_t WHERE document_number=y.document_number) and trunc(x.creation_date) = trunc(x.last_update_da te) and trunc(x.last_update_date) = trunc(sysdate)

Vous aimerez peut-être aussi