delete/update/insert by join

//delete
delete from table1 a 
      where exists (select 1 
                      from table2 b 
                     where a.col1 = b.col1)
                     
//insert 
insert into table1 (
       col1,
       col2
)select
       'a',
       'b'
  from dual
 where not exists (select 1
                     from table2
                    where index = ?)

 

 

//update

  update /*+ bypass_ujvc */
         (select col1
                  from table1 a,
                         table2 b
                 where a.seq = b.seq
                   and a.code = '100000002972' )
           set col1 = '100'

PS:/*+ bypass_ujvc */ 这个Hint 的意思是,两个表的关系是1:1

posted on 2012-02-09 14:48  Kevin Kim  阅读(218)  评论(0编辑  收藏  举报

导航