Updates simple SQL with the key issue of research

Hi, I have two tables TA and TB, where TA contains the fields IDS, FULLNAME, TYPE and tuberculosis contains the fields ID, MIDDLENAME
I want to update the names in TB for first names only according to TA where TB.ID = TA.ID and TA. TYPE = 'ABC '.
I wrote this
setting a day of TB B MIDDLENAME set =
(
Select substr (FULLNAME, instr (FULLNAME, ' ') + 1, instr (FULLNAME, ' ', 1) - length (FIRSTNAME) - 2) of
(
SELECT ID, FULLNAME, substr (FULLNAME, 1, instr (FULLNAME, ' ')-1) first NAME
Ta
where TYPE = 'ABC '.
) AT
where A.ID = B.ID
)

I want to know if there may be no optimization because this SQL is super slow at the moment.
Server Oracle 11 g is
Thank you!

Maybe (easier to write, you can use the fusion too)

update (select b.middlename existing_middle,
        substr(a.fullname,
               instr(a.fullname,' ',1,1) + 1,
               instr(a.fullname,' ',-1,1) - instr(a.fullname,' ',1,1) - 1
              ) extracted_middle
          from tb b,
               ta a
         where a.id = b.id
           and a.type = 'ABC'
       )
   set existing_middle = extracted_middle

Have no where clause after update, you update all lines

update TB B
  set MIDDLENAME = (select substr(FULLNAME,instr(FULLNAME,' ') + 1,instr(FULLNAME,' ', -1) - length(FIRSTNAME) - 2)
                      from (select ID,FULLNAME,substr(FULLNAME,1,instr(FULLNAME, ' ') - 1) FIRSTNAME
                             from TA
                            where TYPE = 'ABC'
                           ) A
                     where A.ID = B.ID
                   )

Concerning

Etbin

Edited by: Etbin on 28.7.2012 10:13

merge into tb b
using (select id,
              substr(fullname,
                     instr(fullname,' ',1,1) + 1,
                     instr(fullname,' ',-1,1) - instr(fullname,' ',1,1) - 1
                    ) extracted_middle
         from ta
        where type  = 'ABC'
      ) a
   on a.id = b.id
when matched
then update
        set b.middlename = a.extracted_middle

Tags: Database

Similar Questions

Maybe you are looking for