我有一个来自此查询的表格列表
select table_name from all_tab_columns where column_name='EXCN_ID'
我想使用此查询获取所有必需的列
select B.*
from t_int_excn_log A, TABLE B
where A.excn_strt_tm < sysdate-7 and A.excn_id=B.excn_id;
需要您帮助循环表列表,这样,它将代替TABLE,按照上一个查询逐个调用所有表。
答案 0 :(得分:0)
你可以在这种情况下使用游标。
declare @name varchar(200)
declare cur cursor for
select table_name from all_tab_columns where column_name='EXCN_ID'
open cur
fetch next from @name
while @@fetch_status = 0
begin
select B.*
from t_int_excn_log A, @name B
where A.excn_strt_tm < sysdate-7 and A.excn_id=B.excn_id;
fetch next from @name
end
close cur
deallocate cur
答案 1 :(得分:0)
试试这个..
DECLARE CURSOR cur IS
select table_name from all_tab_columns where column_name='EXCN_ID'
FROM occupancy WHERE occupied_dt = SYSDATE;
cur_rec table_name%ROWTYPE;
BEGIN
OPEN cur;
LOOP
FETCH cur INTO cur_rec;
EXIT WHEN Cur%NOTFOUND;
select B.*
from t_int_excn_log A, cur_rec B
where A.excn_strt_tm < sysdate-7 and A.excn_id=B.excn_id;
END LOOP;
CLOSE cur;
END;