I have a hierarchical table on Oracle pl/sql. something like:
create table hierarchical (
id integer primary key,
parent_id references hierarchical ,
name varchar(100));
I need to create a procedure to alter that table so I get a new field that tells, for each node, if it has any children or not.
Is it possible to do the alter and the update in one single procedure?
Any code samples would be much appreciated.
Thanks
You can not do the
ALTER TABLE(DDL) and theUPDATE(DML) in a single step.You will have to do the
ALTER TABLE, followed by theUPDATE.Think twice before doing this though. You can easily find out now if an
idhas any childs with a query.This one would give you the child-count of all top-nodes for example:
Adding an extra column with redundant data will make changing your data more difficult, as you will always have to update the parent too, when adding/removing childs.