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

Similar Messages

  • Efficient way of updating data to database table

    what is the efficient way of updating data to database table  .
    i have huge amount of data in my internal table  , how to use update statement in this case .
    1. database table having 20 fields  ,
    2. one is key field and suppose 20 th field i want to change  .
    3. I have data for only 2 fields , i.e for ( 1 st and last 20 th field ) .
    i can't use update statement in loop , as it is not good practice(hits database several times ) .
    do it effects all the 20 fields for  particular record .

    Hi,
    Use UPDATE statement , check below description from SAP help.
    UPDATE dbtab FROM TABLE itab. or UPDATE (dbtabname) FROM TABLE itab.
    Effect
    Mass update of several lines in a database table.Here, the primary key for identifying the lines tobe updated and the values to be changed are taken from the lines of theinternal table itab. 
    The system field SY-DBCNT contains the number of updated lines,i.e. the number of lines in the internal table itab which havekey values corresponding to lines in the database table.
    Regards
    L Appana

  • 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.

  • Analyzing all tables in schema

    Hello everyone,
    I am used below command to analyze all tables in schema
    EXEC DBMS_STATS.gather_schema_stats (ownname => 'CONTRACT', cascade =>true,estimate_percent => dbms_stats.auto_sample_size);when look at tables in dba_tables, for none of the tables LAST_ANALYZED date is changed to today. But when I did below
    EXECUTE DBMS_STATS.GATHER_TABLE_STATS(ownname => 'CONTRACT', tabname => 'CONT_NAME', method_opt => 'FOR ALL COLUMNS', granularity => 'ALL', cascade => TRUE, degree => DBMS_STATS.DEFAULT_DEGREE);I am see LAST_ANALYZED changed to today in dba_tables.
    If I need to change LAST_ANALYZED to all tables do I need to produce the above command for all tables? There are more then 700 tables for this application.
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    CORE    11.2.0.2.0      Production
    TNS for IBM/AIX RISC System/6000: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production

    user3636719 wrote:
    EXEC DBMS_STATS.gather_schema_stats (ownname => 'CONTRACT', cascade =>true,estimate_percent => dbms_stats.auto_sample_size);
    and
    EXECUTE DBMS_STATS.GATHER_TABLE_STATS(ownname => 'CONTRACT', tabname => 'CONT_NAME', method_opt => 'FOR ALL COLUMNS', granularity => 'ALL', cascade => TRUE, degree => DBMS_STATS.DEFAULT_DEGREE);are fundamentally different, you cannot compare them. In gather_schema_stats, oracle used most defaults, decided none needed new stats collected, so it didn't do anything. In the second, you changed method_opt, granularity and degree etc from default values (as set in your db perhaps), so db went ahead and collected stats.
    You need to look up manual and try to understand the default and non-default behavior for parameters and then make an educated decision. Changing stats randomly is not generally a great idea.

  • Need to update one column of all table in that particular schema

    hi all,
    i am using db10g.
    my task is to update one particular column's value of all the table in that schema.
    to acheive the above
    do i have to write update statement for each table or is there any way to do it in bulk?
    i hope my question make sense.
    Thanks..

    Hi karthick,
    I want to know something which is not related to this thread .
    How to include formatted post while replying to thread .
    I know using will be used  format  code before posting  . But how can we  do  it for posted message .
    I hope you understand my question .
    Thanks in advance .                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to find the frequently updated columns in a table

    Hi ,
    I need to find out all the columns of a tables which are frequently getting updated.
    is there any way that I can achieve this ? I am not sure if any meta data information for DML operations exist in Oracle 9 i. Any input is welcome.
    Thanks in Advance !!

    Thank u , i am thinking the same, Thanks for the suggestion.
    any other idea.... like is there any system table which we can query to get details about these dml operations on a table ?are there any kind of system audit tables in oracle where these get recorded ?

  • Is it possible to update attributes in all tables in a multi entity view

    Hi I have a view based on 4 entities, all of which are a 3 of which are 1 to many relationship with the 4th. The 3 additional entities have 2 or 3 attributes, Id, name, and one entity has a foreign key relating to a different table which I do not care about. The IDs are all updatable in the entity, and none of them are generated from a sequence but are inserted manually, except for the 4th (Master?) which is generated from a sequence.
    I create the view and all the entities are updatable, but in the view when I go to attributes from the other tables, it says updatable never and is grayed out so I cannot change it, even though in the entities tab, it is updatable always.
    So I was wondering if this was possible to do???

    I do not understand really, if it is 2 different tables, it is 2 different primary keys. Why would this even happen? What does it matter if EmployeeID and DepartmentID is both 1??? It just seems that there has to be a simpler way to do this but ok.
    So I go to the AppModule, Java tab and go generate Java class. The original code was
    public ViewObjectImpl getObjektiCRUDView1()
    return (ViewObjectImpl)findViewObject("ObjektiCRUDView1");
    I then copy your code to the best of my limited knowledge and get this
    public ViewObjectImpl getObjektiCRUDView1()
    this.getObjektiCRUDView1().executeEmptyRowSet();
    {Row yourRow = this.getObjektiCRUDView1().createRow();
    this.getObjektiCRUDView1().insertRow(yourRow );
            return (ViewObjectImpl)findViewObject("ObjektiCRUDView1");
    On the first row the getObjektiCRUDView1() is underlined and it says missing method body or declare as abstract.
    I know I did something wrong here but I have no idea what as I am not very good with Java
    Also it is not a jsf page, I create a single jspx page and divided it using the panel splitter so on one side we have an adf table for updating the Objekti database table, and on the other side I have an adf form for updating the Positions table (and later on other tables, I hope to have many forms there)
    Edited by: Dino2dy on Jun 10, 2010 12:02 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • 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

  • 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.

  • 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>>

  • OAF-Checkbox when selected should update column in a table

    Hello,
    I have a requirement to add checkbox to MES Operator page and it should perform the following,
    1) When MES Operator page is opened, it should read attribute1(Y/N) from table and accordingly check/uncheck checkbox.
    2) When checkbox is checked/unchecked in the page, it should write Y/N to attribute1 column of a table.
    I was able to successfully add the checkbox and perform the first requirement by extending the View Object.
    Can someone please tell me how to proceed with the second requirement?
    Thanks in advance.

    Hi ,
    Pls go through this thread this will definitely help you.
    How to get current row value from table when press the submit button
    The problem is that PPR is added through the code which is not considered as table event .
    Need to go with a tricky way ,
    1.) create a new seperate table region using Jdeveloper and it shud be replica of standrad once except the new ppr event addition to the check box.
    2.) Hide the existing table region and create a new stacklayoutbean.
    3.) this stacklayout bean will have the extend property ,there you give the complete path of new custom advanced table region.
    Now you should be able to get the row refernce on the click of check box button.

  • 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

  • Need a way to retrieve list of all tables through a RFM

    I wish to retrieve list of all tables through a RFM.
    I know the table DD02L contains a list of all other tables. I can call the RFM RFC_READ_TABLE with table name DD02L or DD03L as an input parameter. I do not wish to do this way as the table name DD02L might get changed in a future release of SAP and break my external C program.
    The question is - is there any other RFM that would return the list of tables and their properties. Does SWO_QUERY_OBJTYPES or some other SWO_QUERY_* RFMs can be used?
    Any useful info is appreciated.
    Thanks

    Thanks Ramiro.
    If I relay on TFDIR table to get a list of function modules, what are the chances that SAP will rename or get rid of TFDIR in a future release of SAP? I wish to avoid using undocumented interfaces as do not want to change my program in the future.

  • 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.

  • IMovie: whats the fastest way to import and save all original media?

    Good afternoon. Ok I need help please. Is there a way to simply take all the imported original media and just save it all in one fell swoop? Rather than having to import and then process/export clip by clip.
    I thought I had a quicker way just grabbing all the original media from the imported camera (right clicking imovie library > show package contents > original media) untill I tried to play one of the original media files - no sound and it was mov file. I assume mp4 is better???
    I have 2800 hours of video I need to import off my camera. I don't need to modify them at all, aside from the occasional combining of clips into one movie. So I need the fastest way. Importing and then exporting clip by clip will take me forever. I would prefer to just import and then just drag all 50 clips or so into my movies folder. But as stated above that does not seem to work as expected unless I'm missing a step.
    Thank you!

    ps Can I take the original media files (mov format) and batch convert them using handbrake or MPEG streamclip? And if so would the resulting videos then have sound? And which is the best format (container codec whatever) to export them to? Thanks!

Maybe you are looking for