`

oracle合并表数据函数:merger into..

阅读更多
Merger into是oracle9i开始增加的一个函数,用来将两个表的数据合并时,或将一个表的数据添加到另一个表但又不能添加重复数据:
sql语法如下:
    merge into table_name table_alias using (table|view|sub_query) alias on(join condition)
when matched then update set col1=col1_val,col2=col2_val......
when not matched then insert (column_list)values(columns_values)

用法示例:
  create table user_temp as select * from auth_user
然后将user_temp中删除几条数据。
这时再将auth_user表中的数据合并到user_temp中,
merge into user_temp mt using auth_user au on( mt.usr_id=au.usr_id)
when matched then update set usr_name=au.usr_name,usr_password=au.usr_password
when not matched then insert (usr_id,usr_name,org_id,usr_password,usr_status)values(au.usr_id,au.usr_name,au.org_id,au.usr_password,'1')

再查看user_temp表,两个表的数据完全一样.

0
1
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics