Gbase 8s修改所有表中的固定字段

249 阅读1分钟
  create table aaa as 
      select
      t1.tabname -- 表名
      ,t2.colname --字段名
      ,row_number() over (order by t1.tabname  ) as rn
      from
      systables t1 --系统统计表
     inner join
     syscolumns t2 --系统字段表
     on 
     t1.tabid = t2.tabid
     and 
     t1.tabid >= 100 --系统统计表中tabid大于100的才是用户自建表
     and
     t2.colname='active' --指定字段





create procedure "gbaseuser".alter_active() returns varchar(200);
  define re varchar(200);-- 定义存储过程返回值(本存储过程返回值为存储过程结束后响应内容)
  define tab_name varchar(200);--需要更新数据的表名
  define sqls varchar(200);--动态SQL语句
  define cishu int;--循环执行的次数
  define i int;
   	 select count(*) into cishu  from aaa;-- 查询要指定的次数
   	 let i = 1; 
   	 loop
        if i > cishu then
           exit;
        else
           select tabname into tab_name from aaa  where rn=i;--查询需要更新数据的表名
           let sqls = '  update '|| tab_name  ||' set active =1 '  ;--定义动态SQL
           execute immediate sqls; --执行动态SQL
        end if; 
          let i = i + 1;
     end loop;
   	 
   	 select 'over' into re from   dual;--循环结束后响应值
   RETURN re; 
end procedure
;