GBase存过--工作实战
--GBase用的是mysql的语法,这是我目前工作中写过的一个存过,用来查询库里所有表有没有重复的数据
CREATE DEFINER="osg_dwods"@"%" PROCEDURE "get_table_repeat_data"(IN in_database_name varchar(30))
begin
declare v_columnValue varchar(100);
declare v_count integer;
declare v_tableName varchar(100);
declare v_columnId varchar(50);
declare v_sql varchar(1000);
declare done int default 0;
declare rec cursor for
select t.table_name,t.column_name
from `information_schema`.columns t
where t.table_schema = in_database_name
and t.ordinal_position = 1;
declare continue handler for not found set done = 1;
truncate table gbase_table_repeat;
open rec;
out_loop:
loop
fetch next from rec into v_tableName,v_columnId;
if v_columnId is not null then
set v_sql = concat('insert into osg_common.gbase_table_repeat (table_name,column_name,column_value,count)
select ''',v_tableName,''',''',v_columnId,''',t.',v_columnId,',count(1) from ',in_database_name,'.',v_tableName,' t group by t.',v_columnId,' having count(1)>1');
set @vsql = v_sql;
prepare stmt from @vsql;
execute stmt;
deallocate prepare stmt;
end if;
if done = 1 then
leave out_loop;
end if;
end loop;
close rec;
end