Oracle - how to find the specified string table that appears

Requirements: For example, scott test oracle user library Zhang emp table below, ename column of the emp table data in a line 'CLARK'. Red marker part.

SQL> select * from scott.emp;

     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 17-DEC-80        800                    20
      7499 ALLEN      SALESMAN        7698 20-FEB-81          1        300         30
      7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
      7566 JONES      MANAGER         7839 02-APR-81       2975                    20
      7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
      7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
      7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
      7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
      7839 KING       PRESIDENT            17-NOV-81       5000                    10
      7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
      7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
      7900 JAMES      CLERK           7698 03-DEC-81        950                    30
      7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
      7934 MILLER     CLERK           7782 23-JAN-82       1300                    10

But you forgot the 'CLARK' in which the character Zhang table, and how to find out?

Here is the code plsql

set serveroutput on
declare
  v_sql varchar2(2000);
  v_count number;
begin
  for cur in(select t.owner, t.table_name, t.column_name from dba_tab_columns t where t.owner = 'SCOTT') 
    loop
      begin v_sql := 'select count(1) from ' || cur.owner || '.' || cur.table_name || ' where ' || cur.column_name || ' like ''%CLARK%'''; 
      execute immediate v_sql into v_count;
      if(v_count >= 1) then
        dbms_output.put_line(cur.owner || ':' || cur.table_name || ':' || cur.column_name);
      end if;
      exception
        when others then
          null;
      end;
    end loop;
end;    
/

Description:
# If you are not sure which user table, put where t.owner = 'SCOTT' remove full library search, but inefficient to
# execute the code above in plsqldeveloper command window in
results is found in scott user CLARK emp table under the column ename

Guess you like

Origin www.cnblogs.com/ddzj01/p/10949440.html