SELECT * FROM b;
ID,NAME,DELETED
8412890,AG-ENV,0
71294,AG-ENV (DELETE) 71294,1
8412891,AG-EWMV,0
46820,AG-EWMV (DELETE) 46820,1
8412892,AG-GIS,0
61738,AG-GIS (DELETE) 61738,1
DECLARE
CURSOR recstoupdate IS
SELECT b.*, regexp_replace(b.name, ' \(DELETE\).*','') AS namefordel
FROM b
WHERE deleted = '1'
AND EXISTS (SELECT 1 FROM b b1 WHERE b1.deleted = '0' AND b1.name = regexp_replace(b.name, ' \(DELETE\).*',''));
BEGIN
FOR rec IN recstoupdate LOOP
dbms_output.put_line('dele
DELETE FROM b WHERE name = rec.namefordel AND deleted = '0';
dbms_output.put_line('upda
UPDATE b SET b.name = rec.namefordel, b.deleted = '0' WHERE b.id = rec.id AND b.deleted = '1';
END LOOP;
-- commit;
END;
/
SELECT * FROM b;
ID,NAME,DELETED
71294,AG-ENV,0
46820,AG-EWMV,0
61738,AG-GIS,0
hmm, this anonymous pl/sql block first selects all records which were deleted (DELETED='1') but also were
recreated back (AND EXISTS condition).
After this it delete recreated records and update their names and
deleted status back. If you want to make changes permanent remove -- from line
where commit resides, otherwise you should execute rollback;
--d.
Main Topics
Browse All Topics





by: TolomirPosted on 2007-08-16 at 08:00:39ID: 19708804
Just to emphasize the matter:
.......... .......... .......... .......... .......... ..DELETED .......... .......... .......... .......... .......0 .......... .......... .......... .......... .....0 .......... .......... .......... .......... ........0
.......... .......... .......... .......... .......... ..DELETED ....1 .1 .....1
.......... .......... .......... .......... .......... ..DELETED .......... .......... .......... .......... .....0 ....1 .......... .......... .......... .......... ...0 .1 .......... .......... .......... .......... ......0 .....1
.......... .......... .......... .......... .......... ..DELETED .......... .......... .......... .......... .......0 .......... .......... .......... .......... .....0 .......... .......... .......... .......... ........0
We start here:
ID..................NAME..
71294............AG-ENV...
46820............AG-EWMV..
61738............AG-GIS...
Now synchronization fails, we get:
ID..................NAME..
71294............AG-ENV (Delete) 71294.....................
46820............AG-EWMV (Delete) 46820.....................
61738............AG-GIS (Delete) 61738.....................
Now new synchronization is successful, we get:
ID..................NAME..
8412890........AG-ENV.....
71294............AG-ENV (Delete) 71294.....................
8412891........AG-EWMV....
46820............AG-EWMV (Delete) 46820.....................
8412892........AG-GIS.....
61738............AG-GIS (Delete) 61738.....................
---
I want a script that reverts that process back to:
ID..................NAME..
71294............AG-ENV...
46820............AG-EWMV..
61738............AG-GIS...
---
I got oracle 10g standard edition so there is no flashback. Apart from that it might be inconsistent with the other tables... So that script should leave new independent entries alone, just fix the accidential "deleted" groups.
Tolomir