我试图查找某个模式的所有表名,这适用于以下查询:
--for DB2/LUW
select * from sysibm.systables
where CREATOR = 'SCHEMA'
and name like '%CUR%'
and type = 'T';
现在,我想再次筛选这些表,以便只获得那些包含具有特定值的特定字段的表。我已尝试通过使用游标并遍历其行来实现此目的。
begin
declare tableName varchar(255);
declare v_at_end integer default 0;
declare not_found CONDITION FOR SQLSTATE '02000';
declare c1 cursor for
select * from sysibm.systables where CREATOR = 'SCHEMA' and name like '%CUR%' and type = 'T';
declare CONTINUE HANDLER FOR not_found SET v_at_end;
open c1;
fetch_loop:
loop
fetch c1 into tableName;
if v_at_end <>0 THEN
leave fetch_loop;
end if;
--how can I print current tableName? following does not work, but also doesn't throw an error I am using AQT:
call DBMS_OUTPUT.PUT_LINE(tableName);
--no kind of select works here, why? (SQL0104N SQLSTATE=42601)
-- tested with:
-- select * from SCHEMA.A_TABLE_NAME;
-- I want to use current tableName, also doesn't work, some tries:
-- select * from SCHEMA.:tableName where fieldName = 123456;
-- select * from :tableName where fieldName = 123456;
-- select name from sysibm.systables where CREATOR = 'SCHEMA' and name = :tableName and type = 'T';
end loop fetch_loop;
close c1;
end;
如何获得所有表名的表包含一个条目与一个特定的字段和值的字段?将很酷输出所有的名称在一个“控制台”或存储在一个文件中。
1条答案
按热度按时间ezykj2lf1#
试试看: