I am trying to write a procedure that uses a dynamic query to fetch records in different tables.Now I want to add a where condition to this clause. The procedure takes an input parameter and I want to use this parameter to compare the value of the same parameter present within the table. The following code doesn't work and I am not sure how to get it to work.
SQL> create or replace procedure p_count(x IN varchar2) as
2 type arr is varray(5) of varchar2(30);
3 tables arr := arr('tb1', 'tb2', 'tb3');
4 cnt number;
5 begin
6 for i in 1 .. tables.count loop
7 execute immediate 'select count(*) from ' || tables(i) ||' where tables(i).column_name ='||x into cnt;
8 insert into tb6 values(tables(i), cnt);
9 end loop;
10 end;
11 /
select count(*) from tb1 where tb1.category = 'A'?