Connor and Chris will both be at AI World from October 12 to October 17 , the premier Oracle conference of 2025. If you're in Vegas, please come say Hi or pop into our sessions
Thanks for the question.
Asked: November 16, 2016 - 8:55 pm UTC
Last updated: November 18, 2016 - 4:16 am UTC
Version: Oracle 11g
Viewed 1000+ times
SQL> drop table t purge; Table dropped. SQL> create table t ( tname varchar2(30), colname varchar2(30)); Table created. SQL> SQL> insert into t values ('DEPT','DNAME'); 1 row created. SQL> insert into t values ('EMP','ENAME'); 1 row created. SQL> SQL> set serverout on SQL> declare 2 c int; 3 string_to_look_for varchar2(10) := 'AL'; 4 begin 5 for i in ( select * from t ) loop 6 execute immediate 7 'select count(*) from scott.'||i.tname||' where '||i.colname||' like ''%'||string_to_look_for||'%''' 8 into c; 9 10 dbms_output.put_line('Found '||c||' occurrences in '||i.tname); 11 end loop; 12 end; 13 / Found 1 occurrences in DEPT Found 1 occurrences in EMP PL/SQL procedure successfully completed. SQL> SQL> set serverout on SQL> declare 2 c int; 3 string_to_look_for varchar2(10) := 'A'; 4 begin 5 for i in ( select * from t ) loop 6 execute immediate 7 'select count(*) from scott.'||i.tname||' where '||i.colname||' like ''%'||string_to_look_for||'%''' 8 into c; 9 10 dbms_output.put_line('Found '||c||' occurrences in '||i.tname); 11 end loop; 12 end; 13 / Found 4 occurrences in DEPT Found 7 occurrences in EMP PL/SQL procedure successfully completed. SQL> SQL>
sirisha, November 17, 2016 - 7:02 pm UTC
Check out more PL/SQL tutorials on our LiveSQL tool.
PL/SQL reference manual from the Oracle documentation library