|  | 
	| 
		
			| Re: find value in table (don't know column name yet) [message #624005 is a reply to message #624001] | Wed, 17 September 2014 03:53   |  
			| 
				
				
					| Lalit Kumar B Messages: 3174
 Registered: May 2013
 Location: World Wide on the Web
 | Senior Member |  |  |  
	| For example, let's say I want to know the TABLE_NAME and COLUMN_NAME having the value 'SCOTT'. My test case is a simple one, I know SCOTT is an employee name in EMP table in ENAME column of standard SCOTT schema. 
 
 
SQL> set serveroutput on;
SQL> DECLARE
  2      lcount NUMBER;
  3      lquery VARCHAR2(200);
  4  BEGIN
  5      FOR data IN (SELECT *
  6                   FROM   user_tab_columns) LOOP
  7          lquery := 'select count(*) from '
  8                    ||data.table_name
  9                    ||' where '
 10                    ||data.column_name
 11                    ||' like ''%SCOTT%''';
 12
 13          EXECUTE IMMEDIATE lquery INTO lcount;
 14
 15          IF lcount > 0 THEN
 16            dbms_output.Put_line(data.column_name
 17                                 ||'-----'
 18                                 ||data.table_name);
 19          END IF;
 20      END LOOP;
 21  END;
 22  /
ENAME-----EMP
PL/SQL procedure successfully completed.
SQL>
 I believe, since you are on 11g, there should be better approach using XML solutions.
 
 
 Regards,
 Lalit
 |  
	|  |  | 
	| 
		
			| Re: find value in table (don't know column name yet) [message #624008 is a reply to message #624001] | Wed, 17 September 2014 03:57   |  
			| 
				
				|  | jgjeetu Messages: 373
 Registered: July 2013
 Location: www.Orafaq.com/Forum
 | Senior Member |  
 |  |  
	| Do one thing , select * from table by concatenating all column names and give that an alias name . and use a condition 'where aliasname like '%value%'
 for ex.
 
 i want to find value 10 in dept table.
 then the query will be
 
 
 SELECT *
  FROM (SELECT deptno ||'-'|| dname ||'-'|| loc VALUE
          FROM dept)
 WHERE VALUE LIKE '%10%';
 maybe this will work for you.
 thanks
 
 
 [Updated on: Wed, 17 September 2014 04:00] Report message to a moderator |  
	|  |  | 
	|  | 
	|  | 
	| 
		
			| Re: find value in table (don't know column name yet) [message #624023 is a reply to message #624015] | Wed, 17 September 2014 05:19   |  
			| 
				
				|  | ecivgamer Messages: 147
 Registered: May 2011
 Location: Ukraine
 | Senior Member |  |  |  
	| Finally, I use this code, it works just fine: 
 
 set serveroutput on;
DECLARE
    lcount NUMBER;
    lquery VARCHAR2(200);
BEGIN
    FOR data IN (
                 SELECT * FROM   ALL_TAB_COLUMNS
                 where TABLE_NAME LIKE UPPER('dbt_reserve') 
                   and COLUMN_NAME NOT IN ('MFDEALID')
                ) 
     LOOP
        lquery := 'select count(*) from ' --creator.dbt_reserve'
                  ||data.owner
                  ||'.'  
                  ||data.table_name
                  ||' where ISAPPROVED = 1 AND ARCDATE = DATE ''2013-09-30'' AND  '
                  ||'(' 
                  || data.column_name
                  ||' like ''127638'''
                  ||' OR ' 
                  || data.column_name
                  ||' like ''127639'''
                  ||')' ;
         EXECUTE IMMEDIATE lquery INTO lcount;
          IF lcount > 0 THEN
             RAISE_APPLICATION_ERROR(-20001, LCOUNT || '----' || DATA.COLUMN_NAME || '-----------' || DATA.TABLE_NAME);
--            dbms_output.Put_line(data.column_name
--                                 ||'-----'
--                                 ||data.table_name);
          END IF;
     END LOOP;
END;
 Big thanks!
 [Updated on: Wed, 17 September 2014 05:23] Report message to a moderator |  
	|  |  | 
	|  | 
	|  | 
	|  | 
	|  |