简体   繁体   中英

Oracle select/update fieldA where fieldA exists Instr(fieldB) of a different table

I would like to update a Table1.field2 where I find Table1.field1 within Table2.field1

Example:

UPDATE Table1 t1 
   SET t1.field2 = 'yes' 
 where Instr(t2.field1, Table2.field1) > 0 

I've tried this a few other ways and I understand my example is definable not the way to do it. I just think it demonstrates best what I'm trying to achieve.

Thanks

The Join like below would be ending up in cartesian result

UPDATE Table1 t1 SET t1.field2 = 'yes' 
where EXISTS
(SELECT 'X' FROM Table2 t2 where Instr(t1.field1, t2.field1) > 0 

Use an exists clause.

UPDATE Table1 t1
   SET t1.field2 = 'YES'
 WHERE EXISTS
          (SELECT 1
             FROM Table2 t2 
            WHERE t1.primary_key = t2.foreign_key
             and INSTR (t1.field1, t2.field1) > 0);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM