I have been reading on Oracle hierarchical queries and all of the documentation/examples seem to be focused on SELECTing.
I have a table with parent-child relations and would like to change parents of children. Everything is done on the same table.
- I can select current parents
- I can select new parents
- Old/new parent pairs have a common (otherwise unique) identifier
The data looks something like this:
ID | DISABLED | NAME | PARAM | PARENT 1 | 1 | qwer | 1 | NULL 2 | NULL | qwer | 2 | NULL 3 | NULL | tyui | 3 | 1
I would like to update the table so that entry 3 is parented to 2 instead of 1. Of course there are multiple disabled roots so handwriting updates would be a pain.
I cannot find examples to at least get on track with this, so anything would be appreciated.
I can do this with LOOPs, something like:
DECLARE CURSOR c1 IS SELECT OLDPARENT, NEWPARENT FROM <...>; BEGIN FOR item IN c1 LOOP EXECUTE IMMEDIATE 'UPDATE <...>' END LOOP; END;
But performance of such query is dreadful.