Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 240323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:39:25+00:00 2026-05-11T20:39:25+00:00

I am working with an Oracle 10g Database. I have the following two tables:

  • 0

I am working with an Oracle 10g Database.

I have the following two tables:

T_DEBTOR :
    - ID_DEBTOR
    - HEADER
T_ELEMENT :
    - ID_ELEMENT
    - ID_DEBTOR
    - INSURER

These two tables are joined using the ID_DEBTOR field.

I want to update the T_ELEMENT.INSURER value with the associated T_DEBTOR.HEADER only if HEADER is not null.
In others words:

If T_DEBTOR.HEADER != null
    Then T_ELEMENT.INSURER = T_DEBTOR.HEADER
    Else T_ELEMENT.INSURER is not modified!

I tried to use the following SQL query:

update
    T_ELEMENT elt
    set elt.INSURER = (
        select HEADER
            from T_DEBTOR debtor
            where
                debtor.HEADER is not null
                and debtor.ID_DEBTOR = elt.ID_DEBTOR);

This query is working for all elements linked to debtors that has a HEADER not null.
However, when the T_DEBTOR.HEADER is null, then this query set the T_ELEMENT.INSURER to null, which is not correct.

ie:

If T_DEBTOR.HEADER != null
    Then T_ELEMENT.INSURER = T_DEBTOR.HEADER   --> This part is OK
    Else T_ELEMENT.INSURER is set to null      --> This part is NOT OK

What is wrong with my query?

Edit, regarding the Brian Storrar answer:

What I want to do is something like that:

update
    T_ELEMENT elt
    set elt.INSURER = (
        select HEADER
            from T_DEBTOR debtor
            where
                debtor.HEADER is not null
                and debtor.ID_DEBTOR = elt.ID_DEBTOR)
    where debtor.HEADER is not null;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T20:39:25+00:00Added an answer on May 11, 2026 at 8:39 pm

    Good question.

    To simulate your situation, I’ve created sample tables:

    SQL> create table t_debtor(id_debtor,header)
      2  as
      3  select 1, 'Header 1' from dual union all
      4  select 2, null from dual union all
      5  select 3, 'Header 3' from dual
      6  /
    
    Tabel is aangemaakt.
    
    SQL> create table t_element (id_element,id_debtor,insurer)
      2  as
      3  select 1, 1, 'to be updated' from dual union all
      4  select 2, 1, 'to be updated' from dual union all
      5  select 3, 2, 'not to be updated' from dual union all
      6  select 4, 2, 'not to be updated' from dual union all
      7  select 5, 3, 'to be updated' from dual
      8  /
    
    Tabel is aangemaakt.
    

    And with your current update statement, the problem becomes clear: the “not to be updated” values are set to NULL:

    SQL> update
      2      T_ELEMENT elt
      3      set elt.INSURER = (
      4          select HEADER
      5              from T_DEBTOR debtor
      6              where
      7                  debtor.HEADER is not null
      8                  and debtor.ID_DEBTOR = elt.ID_DEBTOR)
      9  /
    
    5 rijen zijn bijgewerkt.
    
    SQL> select * from t_element
      2  /
    
    ID_ELEMENT  ID_DEBTOR INSURER
    ---------- ---------- -----------------
             1          1 Header 1
             2          1 Header 1
             3          2
             4          2
             5          3 Header 3
    
    5 rijen zijn geselecteerd.
    

    The best way to do this update, is to update a join of both tables. There are some restrictions however:

    SQL> rollback
      2  /
    
    Rollback is voltooid.
    
    SQL> update ( select elt.insurer
      2                , dtr.header
      3             from t_element elt
      4                , t_debtor dtr
      5            where elt.id_debtor = dtr.id_debtor
      6              and dtr.header is not null
      7         )
      8     set insurer = header
      9  /
       set insurer = header
           *
    FOUT in regel 8:
    .ORA-01779: cannot modify a column which maps to a non key-preserved table
    

    With the bypass ujvc hint, we can circumvent this restriction.
    But it is not advisable to do so unless you know really really sure that t_debtor.id_debtor is unique.

    SQL> update /*+ bypass_ujvc */
      2         ( select elt.insurer
      3                , dtr.header
      4             from t_element elt
      5                , t_debtor dtr
      6            where elt.id_debtor = dtr.id_debtor
      7              and dtr.header is not null
      8         )
      9     set insurer = header
     10  /
    
    3 rijen zijn bijgewerkt.
    
    SQL> select * from t_element
      2  /
    
    ID_ELEMENT  ID_DEBTOR INSURER
    ---------- ---------- -----------------
             1          1 Header 1
             2          1 Header 1
             3          2 not to be updated
             4          2 not to be updated
             5          3 Header 3
    
    5 rijen zijn geselecteerd.
    

    It’s better to just add a primary key. You’ll probably have this one already in place:

    SQL> rollback
      2  /
    
    Rollback is voltooid.
    
    SQL> alter table t_debtor add primary key (id_debtor)
      2  /
    
    Tabel is gewijzigd.
    
    SQL> update ( select elt.insurer
      2                , dtr.header
      3             from t_element elt
      4                , t_debtor dtr
      5            where elt.id_debtor = dtr.id_debtor
      6              and dtr.header is not null
      7         )
      8     set insurer = header
      9  /
    
    3 rijen zijn bijgewerkt.
    
    SQL> select * from t_element
      2  /
    
    ID_ELEMENT  ID_DEBTOR INSURER
    ---------- ---------- -----------------
             1          1 Header 1
             2          1 Header 1
             3          2 not to be updated
             4          2 not to be updated
             5          3 Header 3
    
    5 rijen zijn geselecteerd.
    

    Regards,
    Rob.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found out that Oracle Database 10g and 11g treat the following PL/SQL block
I'm working on an Oracle Form (10g) that has two blocks on a single
I have an Excel file (which has data imported from Oracle 10G Database) one
I'm working with some data in an Oracle 10g database, specifically bulk updating and
Say i have the following table, using Oracle 10g ARTIFACT_LABEL | DEPENDANT_ON test1 |
I have a new project working with an existing oracle database. I've always been
I'm working with oracle for the first time, and I have a table called
I'm Working with a new Oracle DB, with one table having the following indexes:
I'm working with Websphere Portal and Oracle. On two occasions last week, I found
I’m currently working on a classic ASP project talking to an Oracle database. I’m

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.