<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.5" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: search for a string in all tables of a schema</title>
	<link>http://laurentschneider.com/wordpress/2006/12/search-for-a-string-in-all-tables-of-a-schema.html</link>
	<description>Oracle Certified Master</description>
	<pubDate>Sun, 07 Sep 2008 07:29:33 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.5</generator>

	<item>
		<title>by: David</title>
		<link>http://laurentschneider.com/wordpress/2006/12/search-for-a-string-in-all-tables-of-a-schema.html#comment-4454</link>
		<pubDate>Fri, 03 Aug 2007 16:18:44 +0000</pubDate>
		<guid>http://laurentschneider.com/wordpress/2006/12/search-for-a-string-in-all-tables-of-a-schema.html#comment-4454</guid>
					<description>Hi Laurent,

Thank you so much for the SQL and PL/SQL here.
This was almost what I wanted.
I needed to do it in a 9i database.
So, I tried using your NO-XML solution because 
9i doesn't have the "regexp_substr" function.
Also, I wanted to use the wildcard '%' in my 
search (again, since 9i doesn't have the 
regular expression function).

So, I modified your code slightly to use 
the "CASE" statement in your NO-XML solution 
and it works great.
I included my change below.
Thanks again,
David
This was such a time saver.

---
create or replace function search_in_table(
  owner varchar2,
  table_name varchar2,
  search_string varchar2)
return varchar2 is
  stmt varchar2(32700);
  col varchar2(32700);
begin
  stmt := 'select ';
  for c in (
    select column_name
    from all_tab_columns
    where all_tab_columns.table_name=search_in_table.table_name
          and all_tab_columns.owner=search_in_table.owner
          and data_type like '%CHAR%' )
  loop
    stmt := stmt &#124;&#124; 'max(case when "'  &#124;&#124; c.column_name &#124;&#124; 
      '" LIKE ''' &#124;&#124; search_string &#124;&#124; ''' then ''' &#124;&#124; c.column_name
      &#124;&#124; ' ''' &#124;&#124; ' else null end) &#124;&#124; ';
  end loop;
  stmt:= stmt&#124;&#124;'nvl2(count(*),null,null) from "'&#124;&#124;
    owner&#124;&#124;'"."'&#124;&#124;table_name&#124;&#124;'"';
  execute immediate stmt into col;
  return col;
end;
/</description>
		<content:encoded><![CDATA[<p>Hi Laurent,</p>
<p>Thank you so much for the SQL and PL/SQL here.<br />
This was almost what I wanted.<br />
I needed to do it in a 9i database.<br />
So, I tried using your NO-XML solution because<br />
9i doesn&#8217;t have the &#8220;regexp_substr&#8221; function.<br />
Also, I wanted to use the wildcard &#8216;%&#8217; in my<br />
search (again, since 9i doesn&#8217;t have the<br />
regular expression function).</p>
<p>So, I modified your code slightly to use<br />
the &#8220;CASE&#8221; statement in your NO-XML solution<br />
and it works great.<br />
I included my change below.<br />
Thanks again,<br />
David<br />
This was such a time saver.</p>
<p>&#8212;<br />
create or replace function search_in_table(<br />
  owner varchar2,<br />
  table_name varchar2,<br />
  search_string varchar2)<br />
return varchar2 is<br />
  stmt varchar2(32700);<br />
  col varchar2(32700);<br />
begin<br />
  stmt := &#8217;select &#8216;;<br />
  for c in (<br />
    select column_name<br />
    from all_tab_columns<br />
    where all_tab_columns.table_name=search_in_table.table_name<br />
          and all_tab_columns.owner=search_in_table.owner<br />
          and data_type like &#8216;%CHAR%&#8217; )<br />
  loop<br />
    stmt := stmt || &#8216;max(case when &#8220;&#8216;  || c.column_name ||<br />
      &#8216;&#8221; LIKE &#8216;'&#8217; || search_string || &#8216;'&#8217; then &#8216;'&#8217; || c.column_name<br />
      || &#8216; &#8216;'&#8217; || &#8216; else null end) || &#8216;;<br />
  end loop;<br />
  stmt:= stmt||&#8217;nvl2(count(*),null,null) from &#8220;&#8216;||<br />
    owner||&#8217;&#8221;.&#8221;&#8216;||table_name||&#8217;&#8221;&#8216;;<br />
  execute immediate stmt into col;<br />
  return col;<br />
end;<br />
/
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Karthik</title>
		<link>http://laurentschneider.com/wordpress/2006/12/search-for-a-string-in-all-tables-of-a-schema.html#comment-4298</link>
		<pubDate>Fri, 20 Jul 2007 04:58:57 +0000</pubDate>
		<guid>http://laurentschneider.com/wordpress/2006/12/search-for-a-string-in-all-tables-of-a-schema.html#comment-4298</guid>
					<description>search for a string in all tables of a schema is working fine for me. But it takes much time. Please suggest me to get the faster result ..</description>
		<content:encoded><![CDATA[<p>search for a string in all tables of a schema is working fine for me. But it takes much time. Please suggest me to get the faster result ..
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Laurent Schneider</title>
		<link>http://laurentschneider.com/wordpress/2006/12/search-for-a-string-in-all-tables-of-a-schema.html#comment-4167</link>
		<pubDate>Wed, 27 Jun 2007 09:32:56 +0000</pubDate>
		<guid>http://laurentschneider.com/wordpress/2006/12/search-for-a-string-in-all-tables-of-a-schema.html#comment-4167</guid>
					<description>you should restrict the datatype to char then

... from user_tables where data_type='CHAR' ...</description>
		<content:encoded><![CDATA[<p>you should restrict the datatype to char then</p>
<p>&#8230; from user_tables where data_type=&#8217;CHAR&#8217; &#8230;
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Itziks</title>
		<link>http://laurentschneider.com/wordpress/2006/12/search-for-a-string-in-all-tables-of-a-schema.html#comment-4162</link>
		<pubDate>Wed, 27 Jun 2007 05:20:34 +0000</pubDate>
		<guid>http://laurentschneider.com/wordpress/2006/12/search-for-a-string-in-all-tables-of-a-schema.html#comment-4162</guid>
					<description>now I getting an Error:
ORA-24812: character set conversion to or from UCS2 failed</description>
		<content:encoded><![CDATA[<p>now I getting an Error:<br />
ORA-24812: character set conversion to or from UCS2 failed
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Laurent Schneider</title>
		<link>http://laurentschneider.com/wordpress/2006/12/search-for-a-string-in-all-tables-of-a-schema.html#comment-4158</link>
		<pubDate>Tue, 26 Jun 2007 11:49:23 +0000</pubDate>
		<guid>http://laurentschneider.com/wordpress/2006/12/search-for-a-string-in-all-tables-of-a-schema.html#comment-4158</guid>
					<description>&lt;i&gt;
drop table t;
create table t(x char(16));
insert into t values('0b18000432c21111');
select table_name,column_name from (
  select rownum,table_name, regexp_substr(dbms_xmlgen.getxml(
    'select * from "'&#124;&#124;table_name&#124;&#124;'"'),'&#60;[^&#62;]*&#62;0b18000432c21111&#60;/[^&#60;]*&#62;') column_name 
  from user_tables) 
where length(column_name)!=0;
TABLE_NAME                     COLUMN_NAME                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
------------------------------ ---------------------------------------------------------------------------------- 
T                              &#60;X&#62;0b18000432c21111&#60;/X&#62;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
&lt;/i&gt;</description>
		<content:encoded><![CDATA[<p><i><br />
drop table t;<br />
create table t(x char(16));<br />
insert into t values(&#8217;0b18000432c21111&#8242;);<br />
select table_name,column_name from (<br />
  select rownum,table_name, regexp_substr(dbms_xmlgen.getxml(<br />
    &#8217;select * from &#8220;&#8216;||table_name||&#8217;&#8221;&#8216;),&#8217;&lt;[^&gt;]*&gt;0b18000432c21111&lt;/[^&lt;]*&gt;&#8217;) column_name<br />
  from user_tables)<br />
where length(column_name)!=0;<br />
TABLE_NAME                     COLUMN_NAME<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
T                              &lt;X&gt;0b18000432c21111&lt;/X&gt;<br />
</i>
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Itziks</title>
		<link>http://laurentschneider.com/wordpress/2006/12/search-for-a-string-in-all-tables-of-a-schema.html#comment-4157</link>
		<pubDate>Tue, 26 Jun 2007 11:35:00 +0000</pubDate>
		<guid>http://laurentschneider.com/wordpress/2006/12/search-for-a-string-in-all-tables-of-a-schema.html#comment-4157</guid>
					<description>The type is char(16)
the string = 0b18000432c21111
I'm looking for the whole string</description>
		<content:encoded><![CDATA[<p>The type is char(16)<br />
the string = 0b18000432c21111<br />
I&#8217;m looking for the whole string
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Laurent Schneider</title>
		<link>http://laurentschneider.com/wordpress/2006/12/search-for-a-string-in-all-tables-of-a-schema.html#comment-4154</link>
		<pubDate>Mon, 25 Jun 2007 12:19:20 +0000</pubDate>
		<guid>http://laurentschneider.com/wordpress/2006/12/search-for-a-string-in-all-tables-of-a-schema.html#comment-4154</guid>
					<description>in which table does the string exists? what is the datatype? is the string the value of the column, or is it only part of it?</description>
		<content:encoded><![CDATA[<p>in which table does the string exists? what is the datatype? is the string the value of the column, or is it only part of it?
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Itziks</title>
		<link>http://laurentschneider.com/wordpress/2006/12/search-for-a-string-in-all-tables-of-a-schema.html#comment-4153</link>
		<pubDate>Mon, 25 Jun 2007 12:01:43 +0000</pubDate>
		<guid>http://laurentschneider.com/wordpress/2006/12/search-for-a-string-in-all-tables-of-a-schema.html#comment-4153</guid>
					<description>oracle release 10.2.0.1.0 
string= 0b123a</description>
		<content:encoded><![CDATA[<p>oracle release 10.2.0.1.0<br />
string= 0b123a
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Laurent Schneider</title>
		<link>http://laurentschneider.com/wordpress/2006/12/search-for-a-string-in-all-tables-of-a-schema.html#comment-4149</link>
		<pubDate>Sun, 24 Jun 2007 20:38:22 +0000</pubDate>
		<guid>http://laurentschneider.com/wordpress/2006/12/search-for-a-string-in-all-tables-of-a-schema.html#comment-4149</guid>
					<description>any reproducible example to post? version?</description>
		<content:encoded><![CDATA[<p>any reproducible example to post? version?
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Itziks</title>
		<link>http://laurentschneider.com/wordpress/2006/12/search-for-a-string-in-all-tables-of-a-schema.html#comment-4141</link>
		<pubDate>Sun, 24 Jun 2007 13:31:04 +0000</pubDate>
		<guid>http://laurentschneider.com/wordpress/2006/12/search-for-a-string-in-all-tables-of-a-schema.html#comment-4141</guid>
					<description>I was tring to run the search string query but I didn't get any result even on string that I know that exist, I'm using sqlplus</description>
		<content:encoded><![CDATA[<p>I was tring to run the search string query but I didn&#8217;t get any result even on string that I know that exist, I&#8217;m using sqlplus
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
