Search for column in all tables

I want to search for a column value(example instance_id=123456) in all the tables using one query rather than describing each table to find first if instance id exist and if so do a select from that table.

You could try some sort of variation of this:
DECLARE
   value_of_interest    NUMBER := 12345;
   vTable          ALL_TAB_COLS.TABLE_NAME%TYPE;
   vExist          ALL_TAB_COLS.COLUMN_NAME%TYPE;
BEGIN
   DBMS_OUTPUT.PUT_LINE(RPAD('TABLE',45,' ') || ' ' || 'EXISTS');
   FOR rec in (SELECT TABLE_NAME FROM ALL_TAB_COLS WHERE COLUMN_NAME='INSTANCE_ID')
           LOOP
                   EXECUTE IMMEDIATE 'SELECT ''' || rec.table_name || ''' AS TAB,DECODE(count(*),0,''NO'',''YES'') AS EXIST FROM '
                           ||  rec.table_name
                           || ' WHERE INSTANCE_ID=:value '
                           || 'GROUP BY ''' || rec.table_name || '''' INTO vTable,vExist USING value_of_interest;
                   DBMS_OUTPUT.PUT_LINE(RPAD(vTable,45,' ') || ' ' || vExist);
           END LOOP;
EXCEPTION
   WHEN NO_DATA_FOUND THEN
           DBMS_OUTPUT.PUT_LINE('No Results found!');
END;Please be aware this that has not been tested, and may have to be modified for your use.

Similar Messages

  • How to search all columns of all tables in a database

    i need to search all columns of all tables in a database , i already write the code below , but i've got the error message below when run this script
    DECLARE
    cnt number;
    v_data VARCHAR2(20);
    BEGIN
    v_data :='5C4CA98EAC4C';
    FOR t1 IN (SELECT table_name, column_name FROM all_tab_cols where owner='admin' and DATA_TYPE='VARCHAR2') LOOP
    EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ' ||t1.table_name|| ' WHERE ' ||t1.column_name || ' = :1' INTO cnt USING v_data;
    IF cnt > 0 THEN
    dbms_output.put_line( t1.table_name ||' '||t1.column_name||' '||cnt );
    END IF;
    END LOOP;
    END;
    Error report:
    ORA-00933: SQL command not properly ended
    ORA-06512: at line 7
    00933. 00000 - "SQL command not properly ended"
    *Cause:   
    *Action:
    Any help please

    SQL solutions by Michaels
    michaels>  var val varchar2(5)
    michaels>  exec :val := 'as'
    PL/SQL procedure successfully completed.
    michaels>  select distinct substr (:val, 1, 11) "Searchword",
                    substr (table_name, 1, 14) "Table",
                    substr (t.column_value.getstringval (), 1, 50) "Column/Value"
               from cols,
                    table
                       (xmlsequence
                           (dbms_xmlgen.getxmltype ('select ' || column_name
                                                    || ' from ' || table_name
                                                    || ' where upper('
                                                    || column_name
                                                    || ') like upper(''%' || :val
                                                    || '%'')'
                                                   ).extract ('ROWSET/ROW/*')
                       ) t
    --        where table_name in ('EMPLOYEES', 'JOB_HISTORY', 'DEPARTMENTS')
           order by "Table"or
    11g upwards
    SQL> select table_name,
           column_name,
           :search_string search_string,
           result
      from (select column_name,
                   table_name,
                   'ora:view("' || table_name || '")/ROW/' || column_name || '[ora:contains(text(),"%' || :search_string || '%") > 0]' str
              from cols
             where table_name in ('EMP', 'DEPT')),
           xmltable (str columns result varchar2(10) path '.')
    TABLE_NAME                     COLUMN_NAME                    SEARCH_STRING                    RESULT   
    DEPT                           DNAME                          es                               RESEARCH 
    EMP                            ENAME                          es                               JAMES    
    EMP                            JOB                            es                               SALESMAN 
    EMP                            JOB                            es                               SALESMAN 
    4 rows selected.

  • Is there a way to search for and install all uninstalled fonts? I'm getting bored of opening all the files up.

    I've got a file of about 100 typefaces, which is 1000s of fonts. I want to install them all but I dont want to have to open each file and install them all individually (or in small groups).
    So is there a way to search for and install ALL uninstalled fonts in one hit?
    Cheers.

    The best solution I've come across so far is to dump all movies into a shareware app called iVI. It'll show whether each movie has subtitles or not.

  • Had to restore my Mac Book with Snow Leopard. My i Life disc appears to be damaged, and I can't restore my iPhoto application. I have searched for downloads but all appear to be upgrades. Any ideas on how to restore iphotos

    Had to restore my Mac Book with Snow Leopard. My i Life disc appears to be damaged, and I can't restore my iPhoto application. I have searched for downloads but all appear to be upgrades. Any ideas on how to restore iphotos

    Given what you describe you will have to upgrade Snow Leopard by downloading and installing Mac OS X 10.6.8 Update Combo v1.1. Then go to the App Store and sign in with your Apple ID. Purchase and download Mountain Lion to upgrade your OS. Then purchase the latest upgrades for the iLife applications which includes iPhoto.
    Or you can go on eBay, Google, or Amazon and purchase another copy of the DVD based iLife.

  • How to search all columns of all tables in a database for a keyword?

    Dear Team,
    i have an requirement that : i want to search all the columns of all the tables in the particular database based on the specific key word or an free text.
    example :
    table 1: columns data
    empname sam
    empid 01
    table 2 columns data
    deptname sam
    departmentid 10
    table 3 columns data
    organization name sam
    organization id 1
    when i search for text " SAM"
    it should search me from the entire database, all tables and columns of it and display the result
    output : tablename cloumn value
    table1 empname sam
    table2 deptname sam
    table3 organizationame sam
    the example is just an sample not the real data .
    please help me with sample code or any link related to it .
    thanks in advance

    Hi justin , thanx for the reply
    the basic requirement that we required is ,
    the user will just type the keyword( value in the coumn) he required and it should search all the tables and columns of the table in the database and i have to show this in the front ent in the table format. here the user will analyse the information based on the search .
    it is just like the google search we does( type the keyword in free text) it will display the result.
    so for that i have to search entire table and columns in the whole database.
    please if any one provides me the solution it will be help full for me.
    thanx in advance

  • Search for column name in DB tables

    Hi Guys
    Is it possible to search column name when we do not know the corresponding table in the databse
    Cheers
    shabar

    You can use the data dictionary to search though a list of all column names. The <strike>table</strike> data dictionary view is ALL_TAB_COLUMNS.
    Lets assume you want to search for ID columns:
    example
    select owner, table_name, column_name
    from all_tab_columns
    where column_name = 'ID';Edited by: Sven W. on Jun 21, 2011 1:47 PM

  • How to make allow null for a column in all table.

    Hi,
    I have a column "col1" in all tables (user made table) , i want to make it allow null
    please tel me how can it be done using single script.
    i mean in short way.
    yours sincerely.

    yes. absolutely you can.
    Look, what i got -
    Ranit>>  select 'alter table ' || table_name || ' modify("TIMESTAMP" null) ; ' from user_tab_columns where column_name='TIMESTAMP' and nullable ='N';
    'ALTERTABLE'||TABLE_NAME||'MODIFY("TIMESTAMP"NULL);'                           
    alter table FIXED_OBJ$ modify("TIMESTAMP" null) ;                              
    alter table SUMPARTLOG$ modify("TIMESTAMP" null) ;                             
    alter table SUMDELTA$ modify("TIMESTAMP" null) ;                               
    alter table ALL_SUMDELTA modify("TIMESTAMP" null) ;                            
    alter table DBA_EXP_FILES modify("TIMESTAMP" null) ;                           
    alter table WRI$_DBU_CPU_USAGE modify("TIMESTAMP" null) ;                      
    alter table DBA_CPU_USAGE_STATISTICS modify("TIMESTAMP" null) ;                
    7 rows selected.But, it is not over.
    Either - You have to do an 'EXECUTE IMMEDIATE' over these 'alter' scripts.
    OR - Take these scripts, put it into a <script_name>.sql file and then execute this file.
    Hope you understand.
    Edited by: ranit B on Dec 22, 2012 3:17 PM
    -- code added

  • Using toad to search for columns in entire datamart

    can anyone inform me if it is possible, using toad, to conduct a "quick search" search though an entire datamart for a specific column name and if possible how?
    eg: column <pubs_visited incambridge> exists in table <things_to_do_in_cambridge> in a datamart and i want to find out if the column <pubs_visited_in_cambridge> is repeated in another table within the datamart.

    <QUOTE> Not really true, all_tab_columns will give you all tables for which you've grant.</QUOTE>
    tried executing the query with both (DBA_TAB_COLUMNS AND ALL_TAB_COLUMNS) and I have received different results (more results with the dba). apparently, the schema i queried in our datamart, does not contain some of the tables that have been listed using the dba function.
    how could it be possible that tables which do not exist in a specified schema get listed when quering using the dba function?

  • Need a Query to search a value from all tables.

    Hi,
    I would like to know, is there any way that we could search a string from all the tables.
    For example I need to find a STRING 'hello world', on which table it presents. I want to search it from all the tables, as there might be a situtation
    where we dont knwo which table the value gets stored.
    REgards
    Suresh

    Run this code ---this is only search for required value in VARCHAR2 column.as per ur requirement u can change it to oher dataype..
    Reply if its helpful to you
    DECLARE
    S SYS_REFCURSOR;
    CURSOR c_user_col IS
    SELECT TABLE_NAME,COLUMN_NAME,DATA_TYPE FROM USER_TAB_COLUMNS,TAB
    WHERE TABLE_NAME=TNAME AND TABTYPE='TABLE'
    ORDER BY TABLE_NAME;
    TYPE TAB_LIST
    IS
    RECORD
    TABLE_NAME VARCHAR2(1000),
    COLUMN_NAME VARCHAR2(1000),
    DATA_TYPE VARCHAR2(100));
    TYPE T_TAB_LIST
    IS
    TABLE OF TAB_LIST;
    L_TAB_LIST T_TAB_LIST := T_TAB_LIST();
    L_STMT CLOB;
    l_exists NUMBER;
    BEGIN
    FOR i IN c_user_col LOOP
    L_TAB_LIST.EXTEND;
    L_TAB_LIST(L_TAB_LIST.LAST).TABLE_NAME := I.TABLE_NAME;
    L_TAB_LIST(L_TAB_LIST.LAST).COLUMN_NAME := i.COLUMN_NAME;
    L_TAB_LIST(L_TAB_LIST.LAST).DATA_TYPE := i.DATA_TYPE;
    END LOOP;
    FOR i in 1..L_TAB_LIST.COUNT LOOP
    l_exists := NULL;
    IF L_TAB_LIST(I).DATA_TYPE = 'VARCHAR2' THEN
    L_STMT := 'SELECT 1 FROM '||L_TAB_LIST(I).TABLE_NAME||' WHERE '||L_TAB_LIST(I).COLUMN_NAME||'=''samplesdfsdfsdf''';
    OPEN S FOR L_STMT;
    FETCH S INTO l_exists;
    CLOSE S;
    IF l_exists IS NULL THEN
    NULL;
    ELSE
    DBMS_OUTPUT.PUT_LINE('Table name: '||L_TAB_LIST(I).TABLE_NAME||'--Column Name: '||L_TAB_LIST(I).COLUMN_NAME);
    DBMS_OUTPUT.PUT_LINE(L_STMT);
    END IF;
    END IF;
    END LOOP;
    END;

  • Search for Data in all schema

    I have user_x
    I know in one of its tables.Column there is a value 99
    I need to write a script to search all tables under the schema form the value of 99 ?

    PLease have a look at the script in :
    http://it.toolbox.com/blogs/david/search-for-a-given-string-in-all-fields-of-an-entire-schema-24074
    It might help you meet your requirement.

  • Fastest way to update column in all tables of schema

    In our schema we have two columns ColA and ColB common in all tables in our schema.
    Suppose these columns have values as below in all tables
    ColA     ColB     
    A1     B11     
    A12     B22     
    ABC     DEF     
    Now we have to update ColA and ColB where we have alphanumeric values in all tables, some tables have few hundred records and some tables have millions of records.
    Could you gurus suggest me with a fastest way to acheive this.
    What we are thinking is to write a procedure where we can input multiple tables which could be updated simultaneously and make a collection within procedure with following values
    ColA     ColA_R     ColB     ColB_R     
    A1     aa     B11     bb     
    A12     aaa     B22     bbb     
    ABC     No Update DEF     No Update     
    So whenever we have value matching A1 update it with value aa if we have value matching B11 update it with value bb and so on.
    Your inputs are welcome so that to acheive this in fastest manner.
    Thanks,
    Tony
    Edited by: tony29743 on Nov 9, 2010 9:15 AM

    I would be tempted to do it something like this:
    Create an index organized table for the cola updates (old_val, new_val) with a PK on old_val and another one for the colb Values. This could possibliy be a single table, depending on how many distinct values there were for cola and colb and if you are sure that "But if colA and colB have value A1 then it will be updated with aa".
    Then do the updates as an updateable join view something like:
    UPDATE (SELECT t1.cola, iot.new_val
            from tab1 t1, new_values_iot iot
            where t1.cola = iot.old_val)
    SET cola = new_valThis would require two rounds of updates, one for cola and one for colb, but they could be parallelized somewhat by distributing the tables to be updated through several pl/sql blocks each updating a different set of tables.
    You may be able to do it in a single query like:
    UPDATE (SELECT t1.cola, t1.colb, iota.new_val new_vala, iotb.new_val new_valb
            from tab1 t1, new_values_iot iota, new_values_iot iotb,
            where t1.cola = iota.old_val and
                  t1.cola = iotb.old_val)
    SET cola = new_vala,
        colb = new_valbHowever, given that you said there were some values in both cola and colb that did not require updating, that may not work since the join will fail on one of cola or colb if that value is not in the IOT, so you will not get all of the rows updated. If, and it is a big if, either both of cola and colb or neither of cola annd colb need to be updated in a single row, it might work. So, looking at your original examples (ABC and DEF do not require updates but A1 does), if there could be as case where cola = 'A1' and colb = 'DEF' then you will have to do it in two updates per table.
    John

  • Script to add not null columns to all tables in database

    Hello,
    I need to add 5 not null columns to my existing database (all tables).
    The problem is that i do not want to loose the current data.
    I need a script so that i need not do this manually for each table.
    Can u suggest?
    Vishal

    Hello,
    I need to add 5 not null columns to my existing database (all tables).
    The problem is that i do not want to loose the current data.
    I need a script so that i need not do this manually for each table.
    Can u suggest?
    Vishal I always follow this step
    1) Alter table <<tablename>> add(<<columnname>> <<datatype>>)
    2) Update <<tablename>> set <<columnname>>=<<anyvalue>>
    3) Alter table <<tablename>> modify(<<columnname>> <<datatype>> not null)
    else
    1) rename <<tablename>> to <<tablenamebk>>
    2) drop table <<tablename>>
    3) Alter table <<tablenamebk>> add(<<columnname>> <<datatype>>)
    4) update <<tablenamebk>> set <<columnname>>=<<anyvalue>>
    5) create table <<tablename>> (with additional columns with not null)
    6) insert into <<tablename>> select * from <<tablenamebk>>

  • All columns of all table in one schema

    Hi
    All,
    Oralce 10.2.0.3
    I want to count all columns in all the table in one particular schema.
    How can I do that?
    which view i should use to count all cloumns of all tables in particular schema?
    Thanks

    vishal patel wrote:
    we needed for our data conversion project..I don't know how you'll use the number of columns in all a schema for data conversion. Some columns are duplicated (e.g. PK/FK), should they really count for two ?
    A data conversion means you should actually know what are the columns used for, not how many they are.
    one more question that count include hidden columns
    what is hidden column used for ? I can not see those columns in actual table.See here an example :
    Re: Difference btwn user_tab_cols & user_tab_columns
    Nicolas.

  • Sum of values in same column of all tables

    On the same sheet, I have multiple tables with the same column (F) titled "AMOUNT".
    I want to get the sum of all the values in that column, from every table, without having to specify each table.
    Is there a way to do this?

    It would be nice to not have to specify each table but it can't be done that way. Nonetheless, it is easy to get those sums. Type in =SUM( then click on the column letter (F in this case) of each of those tables until you have them all then add the closing parenthesis and hit return.

  • Search for records in a table on the basis of a function

    Hi,
    How is it possible to use a function as search criteria in a sql query ?
    For example, I have the following query :
    select a.job_name JOB_NAME, substr(a.job_name,instr(a.job_name,'.',-1)+1) as AUTNAME
    FROM autosys.job a
    where a.job_name like %PRD%' and a.command like '%dsjob%'
    and a.command not like 'substr(a.job_name,instr(a.job_name,'.',-1)+1)';
    This is now working because of the use of function "substr" on the right side of the query.
    How can I write the query so as to find the same result as using this function ?
    Can someone help me out on this ?
    Thanks

    Among other things, you have the quotes in the wrong place in the NOT LIKE predicate. As posted, you are searching for records where command does not contain the literal string substr(a.job_name,instr(a.job_name,'.',-1)+1). I don't think that is really what you are after. You need to concatenate the operators to the results of the SUBSTR function. Something more like:
    SELECT a.job_name job_name,
           SUBSTR(a.job_name, INSTR(a.job_name, '.', -1)+1) as autname
    FROM autosys.job a
    WHERE a.job_name LIKE 'HP.TM.%PRD.%' and
          a.command LIKE '%dsjob.sh%' and
          a.command NOT LIKE '%'||SUBSTR(a.job_name, INSTR(a.job_name, '.', -1)+1)||'%'; John

Maybe you are looking for

  • Open account iBooks Author from Spain (EIN number)

    Dear Sirs, I'm trying to open an account to publish books to iBooks. You ask me the EIN number, but I am not a resident of USA. I am a resident in Spain and declare tax in Spain. How could publish my books with you without the EIN? I can give you any

  • Printing 'material number' in vertical manner in smartforms

    i am printing a smartforms where in the output i have to print a variable in the vertical format.... how can i rotate the variable to print it in the vertical manner... please do help me out.... its very urgent.....

  • Trackpad will not zoom

    Greetings, Just recently, my Magic Trackpad stopped being able to zoom in/out.  Batteries are okay, checked for updates (only found 1.0 update, which is for pre-Mountain Lion platforms), upaired & repaired, and still, no ability to zoom.  It stopped

  • (13-inch, Early 2011) Buying memory/RAM from non-Apple vendors?

    I've read somewhat similar threads here, and I apologize if I'm beleaguering the issue - I just couldn't find a comparable match... I have a MacBook Pro - 13-inch (Early 2011), and I'm needing to up RAM/memory (see below screenshot). Processor  2.3 G

  • Error 43 when open quick time movie

    i have a stranged situation, when i put some movie's on the root of some hard drive (like c or d) its run without any problem. also when i put those movie into some folder that is name is in english (like c:\quicks movie) its run smoothly ..but.. whe