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

    1. <legend id='EU7B0'><style id='EU7B0'><dir id='EU7B0'><q id='EU7B0'></q></dir></style></legend>

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

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

        <tfoot id='EU7B0'></tfoot>

        Oracle 相当于 MySQL INSERT IGNORE?

        时间:2023-09-19
            <i id='CKK3X'><tr id='CKK3X'><dt id='CKK3X'><q id='CKK3X'><span id='CKK3X'><b id='CKK3X'><form id='CKK3X'><ins id='CKK3X'></ins><ul id='CKK3X'></ul><sub id='CKK3X'></sub></form><legend id='CKK3X'></legend><bdo id='CKK3X'><pre id='CKK3X'><center id='CKK3X'></center></pre></bdo></b><th id='CKK3X'></th></span></q></dt></tr></i><div id='CKK3X'><tfoot id='CKK3X'></tfoot><dl id='CKK3X'><fieldset id='CKK3X'></fieldset></dl></div>
            <legend id='CKK3X'><style id='CKK3X'><dir id='CKK3X'><q id='CKK3X'></q></dir></style></legend>

                <tbody id='CKK3X'></tbody>

              1. <small id='CKK3X'></small><noframes id='CKK3X'>

                  <bdo id='CKK3X'></bdo><ul id='CKK3X'></ul>
                  <tfoot id='CKK3X'></tfoot>
                  本文介绍了Oracle 相当于 MySQL INSERT IGNORE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要更新一个查询,以便它在插入前检查重复条目不存在.在 MySQL 中,我可以只使用 INSERT IGNORE,这样如果发现重复记录,它就会跳过插入,但我似乎找不到 Oracle 的等效选项.有什么建议吗?

                  I need to update a query so that it checks that a duplicate entry does not exist before insertion. In MySQL I can just use INSERT IGNORE so that if a duplicate record is found it just skips the insert, but I can't seem to find an equivalent option for Oracle. Any suggestions?

                  推荐答案

                  查看 MERGE 语句.这应该做你想做的 - WHEN NOT MATCHED 子句会做到这一点.

                  Check out the MERGE statement. This should do what you want - it's the WHEN NOT MATCHED clause that will do this.

                  由于 Oracle 缺乏对真正的 VALUES() 子句的支持,具有固定值的单个记录的语法非常笨拙:

                  Do to Oracle's lack of support for a true VALUES() clause the syntax for a single record with fixed values is pretty clumsy though:

                  MERGE INTO your_table yt
                  USING (
                     SELECT 42 as the_pk_value, 
                            'some_value' as some_column
                     FROM dual
                  ) t on (yt.pk = t.the_pke_value) 
                  WHEN NOT MATCHED THEN 
                     INSERT (pk, the_column)
                     VALUES (t.the_pk_value, t.some_column);
                  

                  另一种方法(例如,如果您要从不同的表进行批量加载)是使用 Oracle 的错误日志记录"工具.语句看起来像这样:

                  A different approach (if you are e.g. doing bulk loading from a different table) is to use the "Error logging" facility of Oracle. The statement would look like this:

                   INSERT INTO your_table (col1, col2, col3)
                   SELECT c1, c2, c3
                   FROM staging_table
                   LOG ERRORS INTO errlog ('some comment') REJECT LIMIT UNLIMITED;
                  

                  之后,所有可能抛出错误的行都可以在errlog 表中找到.在使用 DBMS_ERRLOG.CREATE_ERROR_LOG 运行插入之前,您需要手动创建 errlog 表(或您选择的任何名称).

                  Afterwards all rows that would have thrown an error are available in the table errlog. You need to create that errlog table (or whatever name you choose) manually before running the insert using DBMS_ERRLOG.CREATE_ERROR_LOG.

                  详见说明书

                  这篇关于Oracle 相当于 MySQL INSERT IGNORE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:带有 IN 子句参数的 Oracle 存储过程 下一篇:在 Oracle 中连接 SQL 查询的结果

                  相关文章

                  <small id='1lbbh'></small><noframes id='1lbbh'>

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