for x in
(select column_name,'where '||column_name||' is not null' col
from user_tab_columns
where table_name='TDM_CUSTOMERINFO'
and column_name like 'TAG%';) loop
execute immediate '
insert into tdm_bqdm
select custid,'''||x.column_name||''',d_updatetime from TDM_CUSTOMERINFO '||x.col;
end loop ;
可以去掉一层循环
for x in (select table_name,column_name from user_tab_columns where table_name='TDM_CUSTOMERINFO') loop
if x.column_name like 'TAG%' then
execute immediate 'insert into tdm_bqdm select custid,'||x.column_name||',d_updatetime from '||x.table_name;
commit;
end if;