ORA-01779 cannot modify a column which maps to a non key-preserved table












1















I have a following SELECT query -



SELECT C.CASE_TITL_NM,RA.V_CUST_NUMBER
FROM KDD_CASES C
JOIN FCT_RA RA
ON RA.N_RA_ID = C.RA_ID
WHERE UPPER(C.CNTRY_KEY_ID) LIKE '%MANUAL%'
AND C.SCORE_CT IN (99,100)
AND C.STATUS_CD = 'CCD'
AND C.CASE_TITL_NM NOT LIKE 'MANUAL%'


Result of SELECT query



I need to update value in col V_CUST_NUMBER with value in col CASE_TITL_NM so I plugged my SELECT inside following UPDATEstatement and ran it only to get ORA01779 -



    UPDATE (
SELECT C.CASE_TITL_NM,RA.V_CUST_NUMBER
FROM KDD_CASES C
JOIN FCT_RA RA
ON RA.N_RA_ID = C.RA_ID
WHERE UPPER(C.CNTRY_KEY_ID) LIKE '%MANUAL%'
AND C.SCORE_CT IN (99,100)
AND C.STATUS_CD = 'CCD'
AND C.CASE_TITL_NM NOT LIKE 'MANUAL%'
) X
SET X.V_CUST_NUMBER = X.CASE_TITL_NM;

SQL Error: ORA-01779: cannot modify a column which maps to a non key-preserved table
01779. 00000 - "cannot modify a column which maps to a non key-preserved table"
*Cause: An attempt was made to insert or update columns of a join view which
map to a non-key-preserved table.
*Action: Modify the underlying base tables directly.


Can anybody explain what does this error mean and what would be the right UPDATE query?










share|improve this question



























    1















    I have a following SELECT query -



    SELECT C.CASE_TITL_NM,RA.V_CUST_NUMBER
    FROM KDD_CASES C
    JOIN FCT_RA RA
    ON RA.N_RA_ID = C.RA_ID
    WHERE UPPER(C.CNTRY_KEY_ID) LIKE '%MANUAL%'
    AND C.SCORE_CT IN (99,100)
    AND C.STATUS_CD = 'CCD'
    AND C.CASE_TITL_NM NOT LIKE 'MANUAL%'


    Result of SELECT query



    I need to update value in col V_CUST_NUMBER with value in col CASE_TITL_NM so I plugged my SELECT inside following UPDATEstatement and ran it only to get ORA01779 -



        UPDATE (
    SELECT C.CASE_TITL_NM,RA.V_CUST_NUMBER
    FROM KDD_CASES C
    JOIN FCT_RA RA
    ON RA.N_RA_ID = C.RA_ID
    WHERE UPPER(C.CNTRY_KEY_ID) LIKE '%MANUAL%'
    AND C.SCORE_CT IN (99,100)
    AND C.STATUS_CD = 'CCD'
    AND C.CASE_TITL_NM NOT LIKE 'MANUAL%'
    ) X
    SET X.V_CUST_NUMBER = X.CASE_TITL_NM;

    SQL Error: ORA-01779: cannot modify a column which maps to a non key-preserved table
    01779. 00000 - "cannot modify a column which maps to a non key-preserved table"
    *Cause: An attempt was made to insert or update columns of a join view which
    map to a non-key-preserved table.
    *Action: Modify the underlying base tables directly.


    Can anybody explain what does this error mean and what would be the right UPDATE query?










    share|improve this question

























      1












      1








      1








      I have a following SELECT query -



      SELECT C.CASE_TITL_NM,RA.V_CUST_NUMBER
      FROM KDD_CASES C
      JOIN FCT_RA RA
      ON RA.N_RA_ID = C.RA_ID
      WHERE UPPER(C.CNTRY_KEY_ID) LIKE '%MANUAL%'
      AND C.SCORE_CT IN (99,100)
      AND C.STATUS_CD = 'CCD'
      AND C.CASE_TITL_NM NOT LIKE 'MANUAL%'


      Result of SELECT query



      I need to update value in col V_CUST_NUMBER with value in col CASE_TITL_NM so I plugged my SELECT inside following UPDATEstatement and ran it only to get ORA01779 -



          UPDATE (
      SELECT C.CASE_TITL_NM,RA.V_CUST_NUMBER
      FROM KDD_CASES C
      JOIN FCT_RA RA
      ON RA.N_RA_ID = C.RA_ID
      WHERE UPPER(C.CNTRY_KEY_ID) LIKE '%MANUAL%'
      AND C.SCORE_CT IN (99,100)
      AND C.STATUS_CD = 'CCD'
      AND C.CASE_TITL_NM NOT LIKE 'MANUAL%'
      ) X
      SET X.V_CUST_NUMBER = X.CASE_TITL_NM;

      SQL Error: ORA-01779: cannot modify a column which maps to a non key-preserved table
      01779. 00000 - "cannot modify a column which maps to a non key-preserved table"
      *Cause: An attempt was made to insert or update columns of a join view which
      map to a non-key-preserved table.
      *Action: Modify the underlying base tables directly.


      Can anybody explain what does this error mean and what would be the right UPDATE query?










      share|improve this question














      I have a following SELECT query -



      SELECT C.CASE_TITL_NM,RA.V_CUST_NUMBER
      FROM KDD_CASES C
      JOIN FCT_RA RA
      ON RA.N_RA_ID = C.RA_ID
      WHERE UPPER(C.CNTRY_KEY_ID) LIKE '%MANUAL%'
      AND C.SCORE_CT IN (99,100)
      AND C.STATUS_CD = 'CCD'
      AND C.CASE_TITL_NM NOT LIKE 'MANUAL%'


      Result of SELECT query



      I need to update value in col V_CUST_NUMBER with value in col CASE_TITL_NM so I plugged my SELECT inside following UPDATEstatement and ran it only to get ORA01779 -



          UPDATE (
      SELECT C.CASE_TITL_NM,RA.V_CUST_NUMBER
      FROM KDD_CASES C
      JOIN FCT_RA RA
      ON RA.N_RA_ID = C.RA_ID
      WHERE UPPER(C.CNTRY_KEY_ID) LIKE '%MANUAL%'
      AND C.SCORE_CT IN (99,100)
      AND C.STATUS_CD = 'CCD'
      AND C.CASE_TITL_NM NOT LIKE 'MANUAL%'
      ) X
      SET X.V_CUST_NUMBER = X.CASE_TITL_NM;

      SQL Error: ORA-01779: cannot modify a column which maps to a non key-preserved table
      01779. 00000 - "cannot modify a column which maps to a non key-preserved table"
      *Cause: An attempt was made to insert or update columns of a join view which
      map to a non-key-preserved table.
      *Action: Modify the underlying base tables directly.


      Can anybody explain what does this error mean and what would be the right UPDATE query?







      sql oracle sql-update oracle12c






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 20 '18 at 22:04









      Reeya OberoiReeya Oberoi

      3611927




      3611927
























          3 Answers
          3






          active

          oldest

          votes


















          2














          What it means is the query as specified results in an output set that has duplicated rows for RA. Seeing as one RA row maps to two different C rows you cannnot update RA, because there is the potential to try and update the sole RA row to have two different values



          You can try using a MERGE statement, using SQL-that-writes-SQL to create a bunch of UPDATE statements, or modifying the join condition so duplicate rows from RA are not present in the output and the primary key from RA is covered






          share|improve this answer































            0














            Please look here, especially about key preserved




            The updatable view query must unambiguously return each row of the
            modified table only one time. The query must be “key preserved”, which
            means Oracle must be able to use a primary key or unique constraint to
            ensure that each row is only modified once.







            share|improve this answer































              0














              I was able to run my query it by using EXIST clause



              UPDATE FCT_RA F
              SET F.V_CUST_NUMBER = ( SELECT CASE_TITL_NM
              FROM KDD_CASES C
              WHERE F.N_RA_ID = C.RA_ID
              AND UPPER(CNTRY_KEY_ID) LIKE '%MANUAL%'
              AND SCORE_CT IN (99,100)
              AND STATUS_CD = 'CCD'
              AND CASE_TITL_NM NOT LIKE 'MANUAL%')
              WHERE EXISTS ( SELECT 1
              FROM KDD_CASES C
              WHERE F.N_RA_ID = C.RA_ID
              AND UPPER(CNTRY_KEY_ID) LIKE '%MANUAL%'
              AND SCORE_CT IN (99,100)
              AND STATUS_CD = 'CCD'
              AND CASE_TITL_NM NOT LIKE 'MANUAL%');





              share|improve this answer























                Your Answer






                StackExchange.ifUsing("editor", function () {
                StackExchange.using("externalEditor", function () {
                StackExchange.using("snippets", function () {
                StackExchange.snippets.init();
                });
                });
                }, "code-snippets");

                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "1"
                };
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function() {
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled) {
                StackExchange.using("snippets", function() {
                createEditor();
                });
                }
                else {
                createEditor();
                }
                });

                function createEditor() {
                StackExchange.prepareEditor({
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader: {
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                },
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                });


                }
                });














                draft saved

                draft discarded


















                StackExchange.ready(
                function () {
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53402273%2fora-01779-cannot-modify-a-column-which-maps-to-a-non-key-preserved-table%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                2














                What it means is the query as specified results in an output set that has duplicated rows for RA. Seeing as one RA row maps to two different C rows you cannnot update RA, because there is the potential to try and update the sole RA row to have two different values



                You can try using a MERGE statement, using SQL-that-writes-SQL to create a bunch of UPDATE statements, or modifying the join condition so duplicate rows from RA are not present in the output and the primary key from RA is covered






                share|improve this answer




























                  2














                  What it means is the query as specified results in an output set that has duplicated rows for RA. Seeing as one RA row maps to two different C rows you cannnot update RA, because there is the potential to try and update the sole RA row to have two different values



                  You can try using a MERGE statement, using SQL-that-writes-SQL to create a bunch of UPDATE statements, or modifying the join condition so duplicate rows from RA are not present in the output and the primary key from RA is covered






                  share|improve this answer


























                    2












                    2








                    2







                    What it means is the query as specified results in an output set that has duplicated rows for RA. Seeing as one RA row maps to two different C rows you cannnot update RA, because there is the potential to try and update the sole RA row to have two different values



                    You can try using a MERGE statement, using SQL-that-writes-SQL to create a bunch of UPDATE statements, or modifying the join condition so duplicate rows from RA are not present in the output and the primary key from RA is covered






                    share|improve this answer













                    What it means is the query as specified results in an output set that has duplicated rows for RA. Seeing as one RA row maps to two different C rows you cannnot update RA, because there is the potential to try and update the sole RA row to have two different values



                    You can try using a MERGE statement, using SQL-that-writes-SQL to create a bunch of UPDATE statements, or modifying the join condition so duplicate rows from RA are not present in the output and the primary key from RA is covered







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 20 '18 at 23:11









                    Caius JardCaius Jard

                    12k21240




                    12k21240

























                        0














                        Please look here, especially about key preserved




                        The updatable view query must unambiguously return each row of the
                        modified table only one time. The query must be “key preserved”, which
                        means Oracle must be able to use a primary key or unique constraint to
                        ensure that each row is only modified once.







                        share|improve this answer




























                          0














                          Please look here, especially about key preserved




                          The updatable view query must unambiguously return each row of the
                          modified table only one time. The query must be “key preserved”, which
                          means Oracle must be able to use a primary key or unique constraint to
                          ensure that each row is only modified once.







                          share|improve this answer


























                            0












                            0








                            0







                            Please look here, especially about key preserved




                            The updatable view query must unambiguously return each row of the
                            modified table only one time. The query must be “key preserved”, which
                            means Oracle must be able to use a primary key or unique constraint to
                            ensure that each row is only modified once.







                            share|improve this answer













                            Please look here, especially about key preserved




                            The updatable view query must unambiguously return each row of the
                            modified table only one time. The query must be “key preserved”, which
                            means Oracle must be able to use a primary key or unique constraint to
                            ensure that each row is only modified once.








                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 20 '18 at 23:19









                            RGrucaRGruca

                            1614




                            1614























                                0














                                I was able to run my query it by using EXIST clause



                                UPDATE FCT_RA F
                                SET F.V_CUST_NUMBER = ( SELECT CASE_TITL_NM
                                FROM KDD_CASES C
                                WHERE F.N_RA_ID = C.RA_ID
                                AND UPPER(CNTRY_KEY_ID) LIKE '%MANUAL%'
                                AND SCORE_CT IN (99,100)
                                AND STATUS_CD = 'CCD'
                                AND CASE_TITL_NM NOT LIKE 'MANUAL%')
                                WHERE EXISTS ( SELECT 1
                                FROM KDD_CASES C
                                WHERE F.N_RA_ID = C.RA_ID
                                AND UPPER(CNTRY_KEY_ID) LIKE '%MANUAL%'
                                AND SCORE_CT IN (99,100)
                                AND STATUS_CD = 'CCD'
                                AND CASE_TITL_NM NOT LIKE 'MANUAL%');





                                share|improve this answer




























                                  0














                                  I was able to run my query it by using EXIST clause



                                  UPDATE FCT_RA F
                                  SET F.V_CUST_NUMBER = ( SELECT CASE_TITL_NM
                                  FROM KDD_CASES C
                                  WHERE F.N_RA_ID = C.RA_ID
                                  AND UPPER(CNTRY_KEY_ID) LIKE '%MANUAL%'
                                  AND SCORE_CT IN (99,100)
                                  AND STATUS_CD = 'CCD'
                                  AND CASE_TITL_NM NOT LIKE 'MANUAL%')
                                  WHERE EXISTS ( SELECT 1
                                  FROM KDD_CASES C
                                  WHERE F.N_RA_ID = C.RA_ID
                                  AND UPPER(CNTRY_KEY_ID) LIKE '%MANUAL%'
                                  AND SCORE_CT IN (99,100)
                                  AND STATUS_CD = 'CCD'
                                  AND CASE_TITL_NM NOT LIKE 'MANUAL%');





                                  share|improve this answer


























                                    0












                                    0








                                    0







                                    I was able to run my query it by using EXIST clause



                                    UPDATE FCT_RA F
                                    SET F.V_CUST_NUMBER = ( SELECT CASE_TITL_NM
                                    FROM KDD_CASES C
                                    WHERE F.N_RA_ID = C.RA_ID
                                    AND UPPER(CNTRY_KEY_ID) LIKE '%MANUAL%'
                                    AND SCORE_CT IN (99,100)
                                    AND STATUS_CD = 'CCD'
                                    AND CASE_TITL_NM NOT LIKE 'MANUAL%')
                                    WHERE EXISTS ( SELECT 1
                                    FROM KDD_CASES C
                                    WHERE F.N_RA_ID = C.RA_ID
                                    AND UPPER(CNTRY_KEY_ID) LIKE '%MANUAL%'
                                    AND SCORE_CT IN (99,100)
                                    AND STATUS_CD = 'CCD'
                                    AND CASE_TITL_NM NOT LIKE 'MANUAL%');





                                    share|improve this answer













                                    I was able to run my query it by using EXIST clause



                                    UPDATE FCT_RA F
                                    SET F.V_CUST_NUMBER = ( SELECT CASE_TITL_NM
                                    FROM KDD_CASES C
                                    WHERE F.N_RA_ID = C.RA_ID
                                    AND UPPER(CNTRY_KEY_ID) LIKE '%MANUAL%'
                                    AND SCORE_CT IN (99,100)
                                    AND STATUS_CD = 'CCD'
                                    AND CASE_TITL_NM NOT LIKE 'MANUAL%')
                                    WHERE EXISTS ( SELECT 1
                                    FROM KDD_CASES C
                                    WHERE F.N_RA_ID = C.RA_ID
                                    AND UPPER(CNTRY_KEY_ID) LIKE '%MANUAL%'
                                    AND SCORE_CT IN (99,100)
                                    AND STATUS_CD = 'CCD'
                                    AND CASE_TITL_NM NOT LIKE 'MANUAL%');






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Nov 20 '18 at 23:55









                                    Reeya OberoiReeya Oberoi

                                    3611927




                                    3611927






























                                        draft saved

                                        draft discarded




















































                                        Thanks for contributing an answer to Stack Overflow!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid



                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.


                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function () {
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53402273%2fora-01779-cannot-modify-a-column-which-maps-to-a-non-key-preserved-table%23new-answer', 'question_page');
                                        }
                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        這個網誌中的熱門文章

                                        Xamarin.form Move up view when keyboard appear

                                        Post-Redirect-Get with Spring WebFlux and Thymeleaf

                                        Anylogic : not able to use stopDelay()