database - loop through cursor's data and compare for another table's value sql -


i have 2 tables. want desc table 2 after following steps:
1. select name table1 type = 'animal';
2. loop through each names 1. , check table2 i.e o_name = name;
3. check if desc exist o_name.
4. if desc doesnot exist insert 'pet' record on table2.

how do it? have cursor has name table1. thinking loop through cursor's record beyond not being able do. please suggest me:

declare     cursor data         select name          table1         type='animal';     begin      c in data loop         // after can do?? cannot select because there         // multiple rows      end loop;    end; 

/

table1: id | name  | type ---| ----  | -----   1| apple | food   2| ball  | game   3| cat   | animal   4| cow   | animal   5| ball  | game     table2: o_name | desc     ---| ----   apple| eat       cat| pet     cow|   

you still can query , don't need cursor. note databases optimized working on sets of records, , that's sql queries do. cursors should used if other strategies not work.

update table2 set "desc" = 'pet'     "desc" null ,     o_name in (select name table1 "type" = 'animal') 

note desc , type reserved words in oracle, therefore enclosed them in double quotes. single quotes used enclose text literals (strings) in oracle.


Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -