I have two tables. I want to get desc from Table 2 after following steps:
1. Select name from Table1 where type = 'animal';
2. loop through each names from 1. and check for Table2 i.e o_name = name;
3. Then check if desc exist for that o_name.
4. If desc doesnot exist then insert 'pet' for that record on Table2.
How do I do it? For now I have a cursor that has name from Table1. I am thinking to loop through the cursor's record but beyond that I am not being able to do. Please suggest me:
DECLARE
CURSOR DATA is
SELECT name
FROM Table1
where type='animal';
BEGIN
FOR C IN DATA LOOP
// After this what can I do?? I cannot do select into because there will be
// 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|