What is wrong with my update statement with a join in Oracle?

后端 未结 8 1354
梦谈多话
梦谈多话 2021-01-02 20:29

I am working with an Oracle 10g Database.

I have the following two tables:

T_DEBTOR :
    - ID_DEBTOR
    - HEADER
T_ELEMENT :
    -         


        
相关标签:
8条回答
  • 2021-01-02 20:52

    Have you tried

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

    or something similar admittedy this is a bit unselective but I think it will do what you intend.

    0 讨论(0)
  • 2021-01-02 20:54

    I've found a solution to solve my problem (the where clause is added):

    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 exists (
            select null
                from T_DEBTOR debtor
                where debtor.HEADER is not null
                    and debtor.ID_DEBTOR = elt.ID_DEBTOR);
    

    If you have a better solution, do not hesitate to post it!

    0 讨论(0)
提交回复
热议问题