久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

合并來自不同數據庫的 2 個表

Merge 2 Tables from different Databases(合并來自不同數據庫的 2 個表)
本文介紹了合并來自不同數據庫的 2 個表的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

假設我想將來自不同數據庫的 2 個表合并到一個表中,其中包含來自 2 個表的所有數據:

結果看起來像這樣:

結果表中的條目是不是多余的,因為保時捷和大眾有2個條目?或者我可以只在股票"列中添加值,因為標記"列是明確的?

解決方案

  1. 您需要創建到另一個數據庫的數據庫鏈接這里是如何創建數據庫鏈接的示例 http://psoug.org/definition/create_database_link.htm從另一個數據庫創建選擇語句后應該看起來:select * from tableA@"database_link_name"
  2. 然后您需要使用 MERGE 語句從另一個數據庫推送數據,因此合并語句應如下所示.
  3. 您可以在此處閱讀合并語句:https://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_9016.htm#SQLRF01606

    <前><代碼>合并到 result_table res使用(選擇標記、庫存、some_unique_id來自 result_table res2聯合所有選擇標記、庫存、some_unique_id來自 tableA@"database_link_name") diff在 (res.some_unique_id = diff.some_unique_id )當匹配然后更新集 res.mark = diff.mark,res.stock = diff.stock當不匹配時插入(res.mark,資源庫存,res.some_unique_id)價值觀(差異標記,差異股票,diff.some_unique_id);

Hypothetically I want to merge 2 tables from different databases into one table, which includes all the data from the 2 tables:

The result would look like something like this:

Aren't the entries in the result table redundant, because there are 2 entries with Porsche and VW? Or can I just add the values in the column 'stock' because the column 'Mark' is explicit?

解決方案

  1. you need to create database link to another database here is the example on how to create database link http://psoug.org/definition/create_database_link.htm after creating your select statement from another database should look: select * from tableA@"database_link_name"
  2. Then you need to use MERGE statement to push data from another database so the merge statement should look something like this.
  3. you can read about merge statement here: https://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_9016.htm#SQLRF01606

    
    merge into result_table res
    using (select mark, stock, some_unique_id
             from result_table res2
           union all
           select mark, stock, some_unique_id
             from tableA@"database_link_name") diff
    on (res.some_unique_id = diff.some_unique_id )
    when matched then
      update set res.mark = diff.mark, 
                   res.stock = diff.stock
    when not matched then
      insert
        (res.mark, 
             res.stock, 
             res.some_unique_id)
      values
        (diff.mark, 
             diff.stock, 
             diff.some_unique_id);
    

這篇關于合并來自不同數據庫的 2 個表的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個子標記轉換為具有多個分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個表創建視圖?)
Create calculated value based on calculated value inside previous row(根據前一行內的計算值創建計算值)
How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對?) - IT屋-程序員軟件開發技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 国产欧美精品区一区二区三区 | 亚洲精品一区在线观看 | 国产精品有限公司 | 色视频网站| 久久精品国产一区老色匹 | 久久精品国产一区二区电影 | 91精品国产一区二区三区 | www.三级 | 国产黄色在线 | 四虎影院免费在线播放 | 99re99| 精品欧美一区二区三区久久久 | 男女又爽又黄视频 | 中国大陆高清aⅴ毛片 | 欧美1页 | 国产高清视频在线观看 | 亚洲成人高清 | 久久久久国产成人精品亚洲午夜 | 北条麻妃一区二区三区在线视频 | 久久精品二区 | 精品中文字幕久久 | 操操网站 | 色黄爽 | 91一区二区三区 | 久久免费精品 | 精品久久精品 | 国产精品高潮呻吟 | 精品亚洲一区二区三区 | 国产1区2区3区 | 天天干国产 | 午夜在线免费观看 | 97综合在线 | 午夜视频在线观看一区二区 | 国产精品久久久亚洲 | 精品亚洲一区二区三区 | 久久久夜夜夜 | 成人精品久久 | 欧美在线观看一区二区 | 亚洲欧美在线免费观看 | 中文一区二区 | 精品免费视频 |