• <bdo id='uoy98'></bdo><ul id='uoy98'></ul>

      <i id='uoy98'><tr id='uoy98'><dt id='uoy98'><q id='uoy98'><span id='uoy98'><b id='uoy98'><form id='uoy98'><ins id='uoy98'></ins><ul id='uoy98'></ul><sub id='uoy98'></sub></form><legend id='uoy98'></legend><bdo id='uoy98'><pre id='uoy98'><center id='uoy98'></center></pre></bdo></b><th id='uoy98'></th></span></q></dt></tr></i><div id='uoy98'><tfoot id='uoy98'></tfoot><dl id='uoy98'><fieldset id='uoy98'></fieldset></dl></div>
        <tfoot id='uoy98'></tfoot>

        <legend id='uoy98'><style id='uoy98'><dir id='uoy98'><q id='uoy98'></q></dir></style></legend>

        <small id='uoy98'></small><noframes id='uoy98'>

        Oracle:如何 UPSERT(更新或插入表?)

        Oracle: how to UPSERT (update or insert into a table?)(Oracle:如何 UPSERT(更新或插入表?))

        1. <i id='ibSEm'><tr id='ibSEm'><dt id='ibSEm'><q id='ibSEm'><span id='ibSEm'><b id='ibSEm'><form id='ibSEm'><ins id='ibSEm'></ins><ul id='ibSEm'></ul><sub id='ibSEm'></sub></form><legend id='ibSEm'></legend><bdo id='ibSEm'><pre id='ibSEm'><center id='ibSEm'></center></pre></bdo></b><th id='ibSEm'></th></span></q></dt></tr></i><div id='ibSEm'><tfoot id='ibSEm'></tfoot><dl id='ibSEm'><fieldset id='ibSEm'></fieldset></dl></div>

            <small id='ibSEm'></small><noframes id='ibSEm'>

            <tfoot id='ibSEm'></tfoot>
              <tbody id='ibSEm'></tbody>

              <bdo id='ibSEm'></bdo><ul id='ibSEm'></ul>

            • <legend id='ibSEm'><style id='ibSEm'><dir id='ibSEm'><q id='ibSEm'></q></dir></style></legend>
                • 本文介绍了Oracle:如何 UPSERT(更新或插入表?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  UPSERT 操作要么更新要么在表中插入一行,具体取决于该表是否已有与数据匹配的行:

                  The UPSERT operation either updates or inserts a row in a table, depending if the table already has a row that matches the data:

                  if table t has a row exists that has key X:
                      update t set mystuff... where mykey=X
                  else
                      insert into t mystuff...
                  

                  由于 Oracle 没有特定的 UPSERT 语句,那么执行此操作的最佳方法是什么?

                  Since Oracle doesn't have a specific UPSERT statement, what's the best way to do this?

                  推荐答案

                  MERGE(老式方法")的替代方案:

                  An alternative to MERGE (the "old fashioned way"):

                  begin
                     insert into t (mykey, mystuff) 
                        values ('X', 123);
                  exception
                     when dup_val_on_index then
                        update t 
                        set    mystuff = 123 
                        where  mykey = 'X';
                  end;   
                  

                  这篇关于Oracle:如何 UPSERT(更新或插入表?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Select n random rows from SQL Server table(从 SQL Server 表中随机选择 n 行)
                  SQL query to select dates between two dates(用于选择两个日期之间的日期的 SQL 查询)
                  How can I delete using INNER JOIN with SQL Server?(如何在 SQL Server 中使用 INNER JOIN 进行删除?)
                  Table Naming Dilemma: Singular vs. Plural Names(表命名困境:单数与复数名称)
                  INSERT statement conflicted with the FOREIGN KEY constraint - SQL Server(INSERT 语句与 FOREIGN KEY 约束冲突 - SQL Server)
                  How ROWNUM works in pagination query?(ROWNUM 如何在分页查询中工作?)

                    <small id='27Wcl'></small><noframes id='27Wcl'>

                  1. <legend id='27Wcl'><style id='27Wcl'><dir id='27Wcl'><q id='27Wcl'></q></dir></style></legend>
                  2. <i id='27Wcl'><tr id='27Wcl'><dt id='27Wcl'><q id='27Wcl'><span id='27Wcl'><b id='27Wcl'><form id='27Wcl'><ins id='27Wcl'></ins><ul id='27Wcl'></ul><sub id='27Wcl'></sub></form><legend id='27Wcl'></legend><bdo id='27Wcl'><pre id='27Wcl'><center id='27Wcl'></center></pre></bdo></b><th id='27Wcl'></th></span></q></dt></tr></i><div id='27Wcl'><tfoot id='27Wcl'></tfoot><dl id='27Wcl'><fieldset id='27Wcl'></fieldset></dl></div>

                      <tfoot id='27Wcl'></tfoot>
                          <bdo id='27Wcl'></bdo><ul id='27Wcl'></ul>
                            <tbody id='27Wcl'></tbody>