/*
@ jay
@ 09/01/20
@ update重複資料
*/procedure p_upd
(v_table varchar2,
v_column varchar2)as
o_cur1 mytype;
v_num varchar2(20);
sqltxt varchar2(200);
v_var varchar2(1);
begin
/*取單引號*/
select '''' into v_var from dual;
/*查詢有重複的記錄*/
open o_cur1 for 'select '||v_column||'
from
(select '||v_column||',count(*) cnt from '||v_table||' group by name
)where cnt >1';
loop
fetch o_cur1 into v_num;
v_num := v_var||v_num||v_var;
exit when o_cur1%notfound;
sqltxt := 'update '||v_table||' set '||v_column||'='||v_column||'||rownum where '||v_column||' = '||v_num;
execute immediate sqltxt;
end loop;
end;
sql 重覆記錄和重覆記錄數
如果table1有兩個column adress和pepole,那麼下面的sql可以找出table1裡的重覆記錄和重覆記錄數 create table table1 adress nvarchar 10 pepole nvarchar 10 insert table1 select 寧波 張三 nb...
SQL查詢重覆記錄,刪除重覆記錄
1 查詢表中多餘的重覆記錄,重覆記錄是根據單個字段 docid 來判斷 select from tablename where docid in select docid from tablename group by docid h ing count docid 1 例二 select from...
查詢重覆記錄
ifexists select fromdbo.sysobjectswhereid object id n dbo p qry andobjectproperty id,n isprocedure 1 dropprocedure dbo p qry go 查詢重覆記錄的通用儲存過程 可以查詢出表中那...