DBAsupport.com Forums - Powered by vBulletin
Results 1 to 4 of 4

Thread: Update large table based on substring

  1. #1
    Join Date
    Aug 2002
    Posts
    115

    Update large table based on substring

    Hi,

    I have 1 table which has about 20 records...and I need to update another table which has 10 million records using column data from the small table.

    eg:

    table A(small table)

    Column A Column B
    312 412

    table B(large table)

    Column C
    312456
    312789

    I need to update this table B, column C such that the updated values would be

    412456
    412789

    So we would have to use functions (substring) in the update statement.

    What would be the best approach for this?

    Would function based index help? Is there a better way than using function based index?

    Thanks
    Sam

  2. #2
    Join Date
    Aug 2002
    Location
    Colorado Springs
    Posts
    5,253
    Put a PK or UK on TableA.ColumnA, and you can ...

    Code:
    update 
    (
    select tableb.columnC,
             tableA.columnB
    from tableA, tableB
    where tableA.columnA = subStr(tableB.columnc,1,3)
    )
    set columnC = columnB||substr(columnC,4,3)
    /
    David Aldridge,
    "The Oracle Sponge"

    Senior Manager, Business Intelligence Development
    XM Satellite Radio
    Washington, DC

    Oracle ACE

  3. #3
    Join Date
    May 2000
    Location
    ATLANTA, GA, USA
    Posts
    3,135
    Quote Originally Posted by slimdave
    Put a PK or UK on TableA.ColumnA, and you can ...

    Code:
    update 
    (
    select tableb.columnC,
             tableA.columnB
    from tableA, tableB
    where tableA.columnA = subStr(tableB.columnc,1,3)
    )
    set columnC = columnB||substr(columnC,4,3)
    /
    In line view update may not work because the result set of the join may have duplicate rows.

    Tamil
    www.beaconinfotechcorp.com

  4. #4
    Join Date
    Apr 2006
    Posts
    377
    The following update should work if you know that substr(columnC,1,3) is in tablea.columnA:

    Code:
    update tableb b
    	set columnC = (select columnB||substr(b.col3,4,6)
    			from tablea
    			where tablea.columnA = substr(b.columnC,1,3));
    If not, you can modify the update as follows:

    Code:
    update tableb b
    	set columnC = (select columnB||substr(b.col3,4,6)
    			from tablea
    			where tablea.columnA = substr(b.columnC,1,3))
    	where substr(columnC,1,3) in (select columnA from tablea);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width