Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Oracle SQL other database use in update or if

i use ORACLE SQL and i want to Update a table with conditions. One Condition is that in a other database the table is the value null. But i get the error ‘Table, view or sequence reference ‘Db2table.MERGE_UNIT_ID’ not valid in this context.‘ For this I create a new table with the column of the table of DB2 and i want to use it to compare it.

create table db2table as (select r.merge_einheit_id from be_einheit be join DB2.r_be_einheit r on be.id = r.id)
 
begin
    if db2table.merge_einheit_id is null
       then Update be_einheit set be_einheit.CHDATE=sysdate  
          where be_einheit.merge_einheit_id is not null 
          and be_einheit.id= be_container.einheit_id;
    end if;
end;

my second approch is that i add it to the WHERE with an AND, but then i get the Error ‘"DB2"."MERGE_EINHEIT_ID":invalid identifier‘.
Anyone have any idea what this is or how i can get adas problem solved?

begin
 Update be_einheit set be_einheit.CHDATE=sysdate  
     where be_einheit.merge_einheit_id is not null 
     and be_einheit.id= be_container.einheit_id
     and db2table.merge_einheit_id is null;
end;```

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Creating a table won’t help much in long term because that table is a static object; if anything changes in tables you used in CTAS, db2table won’t know anything about it.

If you successfully created db2table, then – according to join condition (join **DB2.**r_be_einheit on) – you aren’t actually talking about other database – it is just another schema in the same database. Furthermore, it means that owner (db2) granted (at least) select privilege on r_be_einheit to you. That’s OK.

To me, it looks as if something like this might do:

update be_einheit be set
  be.einheit.chdate = sysdate
  where exists (select null 
                from db2.r_be_einheit r
                where r.id = be.id
                  and r.merge_einheit_id is null
               )
    and exists (select null
                from be_container bc
                where bc.einheit_id = be.id
               )
    and be.merge_einheit_id is not null;                                
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading