oracle table according to field rapid de-emphasis

--select * from T_FPCPFUNC for update
--select count(*) ct from T_FPCPFUNC group by govyear,govid,sysid,fpguid order by ct desc
declare
--声明
v_temp_table varchar2(32);
v_tablename varchar2(32);
type t_columns is table of varchar2(100); --类型
cols t_columns ; --字段

v_str1 varchar2(100);
v_str2 varchar2(100);
v_sql varchar2(1000);

the begin
v_temp_table: = 'TEMP_DISTINCT'; - temporary table name
v_tablename: = 'T_FPCPFUNC'; - the need to re-table - modify
cols: = t_columns ( 'govyear' , 'govid', 'sysid', ' fpguid '); - ---- deduplication corresponding fields need to be modified
for I in. 1 .. cols.count Loop
v_str1: = v_str1 ||' B '|| cols (I) ||', ';.
v_str2 : = v_str2 || 'A.' || cols (I) || ',';
End Loop;
v_str2: = substr (v_str2,0, length (v_str2) -1);
- create a temporary table, a temporary table and data stored duplicate rowID of
v_sql: = 'Create Table' || || v_temp_table 'AS SELECT' || || v_str1 'b.rowid DataID from AS' || || v_tablename 'Not in b.rowid B WHERE (SELECT MAX (a.ROWID) dataid from '|| v_tablename ||' a GROUP BY '|| v_str2 ||') ';
- A temporary table rowID to delete duplicate data in the database only designated
EXECUTE IMMEDIATE v_sql;
EXECUTE IMMEDIATE 'delete from '||v_tablename||' a where a.rowid in (select b.dataid from '||v_temp_table||' b)';
commit;
--删除临时表
EXECUTE IMMEDIATE'drop table '||v_temp_table;

end;

Guess you like

Origin www.cnblogs.com/sx2zx/p/11458048.html