REM **************************************************************
REM David L. Hunt (file author) distributes this and other
REM files/scripts for educational purposes only, to illustrate the
REM use or application of various computing techniques. Neither the
REM author nor "Dasages, LLC" makes any warranty regarding this
REM script's fitness for any industrial application or purpose nor is
REM there any claim that this or any similarly-distributed scripts
REM are error free or should be used for any purpose other than
REM illustration.
REM
REM Please contact the author via email (dave"at"dasages.com) when
REM you have comments, suggestions, and/or difficulties with this
REM package or its functions.
REM
REM [Please keep the above disclaimer and the embedded electronic
REM documentation with this script.]
REM **************************************************************
REM About this script/file:
REM
REM This script displays (from the current Oracle user/schema) any
REM data object (e.g. table/view), Column name, and content
REM of rows which reside in a table or view having a column matching
REM input prompt "Col_name" and content matching input prompt
REM "Content_Frag".
REM
REM The code also allows user-defined WHERE conditions.
REM
REM In the code, below, 'TABLE' is commented out of the object_type
REM comparisons ["...o.object_type in (/*'TABLE',*/'VIEW')..."].
REM If you wish to have the script search TABLEs, as well, then
REM remove the comment symbols so that the code reads:
REM "...o.object_type in ('TABLE','VIEW')..."
REM **************************************************************
set verify off
set echo off
accept Col_name prompt "Enter the column name for which you are looking: "
accept Content_Frag prompt "Enter (a fragment of) the text for which you are looking: "
prompt
prompt You may enter here an additional condition to search for.
prompt For example: "CustID=1234". If your condition requires single quotes
prompt (to surround a literal, for example), then use two single quotes
prompt as in this example:
prompt
prompt ---> Last_name like ''%Smith%'' <----
prompt
prompt Note: you must ensure that your condition is syntactically correct,
prompt otherwise you will receive a run-time error.
prompt
prompt If you do not need an additional condition, then press [Enter]
prompt
accept WhereCondition prompt "Enter condition ---> "
prompt
prompt ====================================================================
set serveroutput on format wrap
declare
results_cnt number := 0;
sql_stm varchar2(2000);
found_cnt number := 0;
confirmation varchar2(2000);
invalid_identifier exception;
pragma exception_init(invalid_identifier,-904);
errors boolean;
conjunction varchar2(10);
suffix varchar2(100);
procedure suffix_creation is
Begin
suffix := null;
if '&WhereCondition' is not null then
if errors then
conjunction := '..but "';
suffix := ' encountered at least 1 run-time error.';
else
conjunction := '..plus "';
end if;
confirmation := confirmation||conjunction
||replace('&WhereCondition','''''','''')||'"'
||suffix;
end if;
end;
begin
dbms_output.enable(1000000);
dbms_output.put_line(' ');
for t in (select c.table_name, c.column_name
from user_tab_columns c, user_objects o
where column_name = upper('&Col_name')
and c.table_name = o.object_name
and o.object_type in (/*'TABLE',*/'VIEW')) loop
sql_stm := 'select count(*) from '||t.table_name
||' where upper(&col_name) like upper(''%&Content_Frag'||'%'')';
if '&WhereCondition' is not null then
sql_stm := sql_stm||' and &WhereCondition';
end if;
results_cnt := 0;
errors := false;
begin
execute immediate sql_stm into results_cnt;
exception
when invalid_identifier then
dbms_output.put_line
('Error: --> '||t.table_name||'...Invalid identifier in '||
replace('"&WhereCondition".','''''',''''));
errors := true;
when others then
dbms_output.put_line
('Error: --> '||t.table_name||'...syntax error in '||
replace('"&WhereCondition".','''''',''''));
errors := true;
end;
confirmation := null;
if results_cnt > 0 then
found_cnt := found_cnt+1;
suffix_creation;
dbms_output.put_line('Found: --> '||t.table_name||'.'||t.column_name
||' contains "&Content_Frag".'||confirmation);
end if;
end loop;
dbms_output.put_line(' ');
if found_cnt = 1 then
confirmation := '1 object contains "&Content_Frag" '||
'in its "&Col_name" column.';
else
confirmation := found_cnt||' objects contain "&Content_Frag" '||
'in their "&Col_name" column.';
end if;
suffix_creation;
dbms_output.put_line(confirmation);
end;
/
prompt ====================================================================