今天周六在用户那里加班,做数据库中的数据处理工作,只能在没有业务发生的时候进行,没办法!!!
数据处理中涉及的语句,查询某个字段的值在表中是否存在:
declare
var1 number;
begin
for item in (SELECT TABLE_NAME,COLUMN_NAME
FROM XG_TABLENAME
union all
SELECT TABLE_NAME,COLUMN_NAME
FROM XG_TABLENAME_QT
) loop
execute immediate 'select count(1) from ' || item.table_name ||
' where ' || item.column_name || ' = ' || '''150422196909030616'''
into var1;
if var1<>0
then
dbms_output.put_line('var1:' || var1 );
dbms_output.put_line( '表:' || item.table_name || '列:' ||item.column_name );
end if ;
end loop;
end;
var1 number;
begin
for item in (SELECT TABLE_NAME,COLUMN_NAME
FROM XG_TABLENAME
union all
SELECT TABLE_NAME,COLUMN_NAME
FROM XG_TABLENAME_QT
) loop
execute immediate 'select count(1) from ' || item.table_name ||
' where ' || item.column_name || ' = ' || '''150422196909030616'''
into var1;
if var1<>0
then
dbms_output.put_line('var1:' || var1 );
dbms_output.put_line( '表:' || item.table_name || '列:' ||item.column_name );
end if ;
end loop;
end;
批量删除重复数据:
declare
var1 number;
begin
for item in (
SELECT NSRSBH,ZSXH,YZPZXH FROM BAK_SB_PLKK_CFJL_ZSXH_YZPZXH E
WHERE E.ROWID>
(SELECT MIN(X.ROWID) FROM BAK_SB_PLKK_CFJL_ZSXH_YZPZXH X WHERE X.NSRSBH=E.NSRSBH)
) loop
execute immediate 'DELETE FROM SB_SPXX WHERE zsxh= ''' || item.ZSXH||'''';
execute immediate 'DELETE FROM SB_ZSXX WHERE zsxh= ''' || item.ZSXH||'''';
execute immediate 'DELETE FROM sb_yjnsk_lsz WHERE pzhm= ''' || item.YZPZXH||'''';
commit;
end loop;
end;
var1 number;
begin
for item in (
SELECT NSRSBH,ZSXH,YZPZXH FROM BAK_SB_PLKK_CFJL_ZSXH_YZPZXH E
WHERE E.ROWID>
(SELECT MIN(X.ROWID) FROM BAK_SB_PLKK_CFJL_ZSXH_YZPZXH X WHERE X.NSRSBH=E.NSRSBH)
) loop
execute immediate 'DELETE FROM SB_SPXX WHERE zsxh= ''' || item.ZSXH||'''';
execute immediate 'DELETE FROM SB_ZSXX WHERE zsxh= ''' || item.ZSXH||'''';
execute immediate 'DELETE FROM sb_yjnsk_lsz WHERE pzhm= ''' || item.YZPZXH||'''';
commit;
end loop;
end;
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/543979/viewspace-700166/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/543979/viewspace-700166/