Oracle update statement - how do you link to related tables? -


i'm relatively new oracle, having working on ms sql of career. i'm used doing stuff like:

update t set col1 = o.col2 mytable t  join othertable o on t.otherid = o.id 

i tried syntax in oracle, , doesn't accept it. looked in oracle docs , couldn't find example of i'm trying do.

how do it?

option a) correlated subquery

update mytable t   set col1 = (select o.col2 othertable o t.otherid = o.id) 

this requires subquery return no more 1 match each row in table being updated. if returns no match, column updated null, may not want. add where exists (select o.col2 othertable o t.otherid = o.id) cause update occur match found.

option b) updating join view

update (select t.col1, o.col2 mytable t join othertable o on t.otherid = o.id)   set col1 = col2 

this closer used doing. work if oracle can determine unique row in underlying table each row in join -- think means id must unique key of othertable.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -