I am new to Oracle 10g. I have couple of tables as shown below:
INCOME_MASTER
INCOME_ID NUMBER(10) sEQ NUMBER,
INCOME_TYPE VARCHAR2(10),
INCOME_DATE DATE
INCOME_DETAILS
INCOME_DETAILS_SEQ_NO NUMBER(10) SEQUENCE,
INCOME_ID NUMBER(10),
ITEM_ID NUMBER(10),
ITEM_VALUE NUMBER (10,2)
I have lot of values in both the tables.
I need to query all the records from the INCOME_MASTER table and for each each record in INCOME_MASTER table, I need to loop through
SELECT INCOME_ID FROM INCOME_MASTER
select ITEM_VALUE FROM INCOME_DETAILS WHERE INCOME_ID= FROM above query and ITEM_ID=201
select ITEM_VALUE FROM INCOME_DETAILS WHERE INCOME_ID= FROM above query and ITEM_ID=202
select ITEM_VALUE FROM INCOME_DETAILS WHERE INCOME_ID= FROM above query and ITEM_ID=203
select ITEM_VALUE FROM INCOME_DETAILS WHERE INCOME_ID= FROM above query and ITEM_ID=204
I need to add values from ITEM_ID 202,203,204 and deduct the value from ITEM_ID=201 value
whatever value I get I need to insert a new record into INCOME_DETAILS
insert into INCOME_DETAILS
values(INCOME_ID,205,value from above)
I want to do this for all the records in Income_master table