2016-09-19 12 views
0

私は毎月現在のアクティブな行と1つの履歴行を保持する必要があるビットマップテーブルを用意しました。BiTemporalテーブルから行を削除(物理的削除)する方法

IF行が月に重複しているこれらの行を削除する必要があります。行以上から

Policy_ID Customer_ID Validity 

497201 304779902 ('05/06/16', HIGH END) 

    540944 304779902 ('07/25/16', '07/30/16') 

    541077 304779902 ('07/10/16', '07/24/16') 

    541145 304779902 ('07/01/16', '07/10/16') 

    541008 304779902 ('06/20/16', '07/01/16') 

私は


497201 304779902 ('05/06/16', HIGH END) 

    540944 304779902 ('07/25/16', '07/30/16') 

    541008 304779902 ('06/20/16', '07/01/16') 

これを実行するのを助けることができる任意の特定のコマンドを Policy_ID CUSTOMER_IDの妥当性を維持する必要があります。

答えて

0

実際に行を削除するには、NONTEMPORALの削除が必要です。最も簡単な方法は、次のような一時テーブルを使用します。

create volatile table src as 
(select Policy_ID, Customer_ID, Validity 
    from tab 
    qualify 
    row_number() -- find the rows to delete 
    over (partition by Customer_ID order by Validity desc) > 2 
) with data 
primary index (Customer_ID) -- should be the PI of the target table 
on commit preserve rows; 

nontemporal 
delete from tab 
where (Policy_ID, Customer_ID, Validity) 
in (select * from src) 
関連する問題