I have a task where I have to compare all the columns in a schema with the trend of same column. For this I have written a query which generated insert statements in bulk. The total num of insert statements will exceed 50K+. The sql generation query that I have written is as below:
select ' insert into global.PM_COUNTER_AUDIT select ''' || column_name ||
''' COUNTER_NAME, pre.country,pre.city, pre.stddev_col_name , pre.cnt_wk,post.counter_last_day,var_wk from (select country, city,stddev(nvl(' || column_name ||
',0)) stddev_col_name, variance(nvl(' || column_name || ',0)) var_wk, avg(nvl(' || column_name || ',0)) cnt_wk, count(*) from ' || owner || '.' || table_name ||
' where datetime>=trunc(sysdate)-14 and upper(trim(tO_char(datetime,''DAY''))) NOT IN (''FRIDAY'',''SATURDAY'') group by country, city)pre left outer join (select country, city,sum(nvl(' ||
column_name || ',0)) counter_last_day from ' || owner || '.' || table_name ||
' where datetime>=trunc(sysdate)-1 group by country, city )post on pre.country=post.country and pre.city=post.city where counter_last_day not between pre.cnt_wk-(3*(pre.stddev_col_name)) and pre.cnt_wk+(3*(pre.stddev_col_name)) '
from all_tab_cols
where owner = 'HUAWEI_EUTRAN_PM'
and upper(table_name) in ('TABLE_X', 'TABLE_Y', table_z)
and nullable = 'Y'
Now I want to execute all these generated statement using cursor or immediate execute but I am unable to accomplish this. Kindly advise how can I do it.
TIA
SELECT 'select 'insert ....rownumwithout an order-by will give indeterminate results, which might cause you problems.) Converting to a loop is straightforward, but we don't know what problem you are having doing that, and without a working query (preferably simplified a bit) to start from it would be a bit pointless trying.