Pl/Sql Delete Problem
578885May 22 2007 — edited May 23 2007Hi all,
I have the table structure as
table1
Month Currency Amount
APR USD 211
APR USD 234
APR EUR 0
APR EUR 0
APR GBP 0
MAY USD 0
MAY USD 296
MAY EUR 0
MAY EUR 0
MAY GBP 245
I want to delete some rows from this table according to the following rule..
1) for 1-month, 1-currency i want to delete rows with amount =0;
2) Atleast 1 row should come for a currency for a month.
I want a result like
Month Currency Amount
APR USD 211
APR USD 234
APR EUR 0
APR GBP 0
MAY USD 296
MAY EUR 0
MAY GBP 245
If I use a cursor like,
CURSOR DEL
IS
SELECT C, D, A FROM
(
SELECT currency C, month D, COUNT(*) A FROM table1 GROUP BY month, currency
)
WHERE A > 1;
open del;
FETCH DEL INTO DELCURR, DELDATE, DELCOUNT;
EXIT WHEN DEL%NOTFOUND;
DELETE FROM table1 WHERE currency = DELCURR
AND month = DELDATE
and amount = 0;
then i will lose EUR for April and May.
Kindly help.
Thanks in advance..