Will an update in the trigger trigger itself? Oracle PLSQL

oracleplsqltrigger

Here's my PLSQL trigger:

CREATE OR REPLACE TRIGGER ROOT_CHANGING_TRG 
BEFORE UPDATE OF ROOT_ID,PARENT_PHYS_ID ON UNIQUE_PHYSICIAN 
FOR EACH ROW
DECLARE
var_root number := :new.ROOT_ID;
var_par number := :new.UNIQUE_ID;

BEGIN

UPDATE UNIQUE_PHYSICIAN
SET ROOT_ID = var_root
WHERE PARENT_PHYS_ID = var_par;

END;

Will this trigger propagate? Like, if it updates a ROOT_ID for another record, will that trigger its own trigger? Further, if it does trigger that, will it use the new ROOT_ID? I want the ROOT_ID to propagate down the tree I've built.

Edit:

How this works is that each record has a unique ID, a parent ID, and a root ID. I basically have a tree, each member of that tree has a root_ID pointing at the unique ID of the root and a parent ID pointing at the one above it. The root's root and parent IDs are its own unique ID.

in the case that a user manually changes a record to point at a new root and parent, I want all the children of that node to have the new root ID. Is there a better way to do this?

Best Answer

My proposal would be this one:

CREATE TABLE UNIQUE_PHYSICIAN (
    PARENT_PHYS_ID NUMBER,
    PHYS_ID        NUMBER CONSTRAINT PHYSICIAN_PK PRIMARY KEY);

ALTER TABLE DPISYS.UNIQUE_PHYSICIAN ADD CONSTRAINT UNIQUE_PHYSICIAN_PARENT_FK 
   FOREIGN KEY (PARENT_PHYS_ID) REFERENCES DPISYS.UNIQUE_PHYSICIAN (PHYS_ID);

CREATE OR REPLACE TRIGGER ROOT_CHANGING_TRG 
    BEFORE UPDATE OF PHYS_ID ON UNIQUE_PHYSICIAN 
    FOR EACH ROW

BEGIN
    :NEW.PHYS_ID := :OLD.PHYS_ID;
END;

Then the root element(s) is/are the record(s) where PARENT_PHYS_ID IS NULL.

For PHYS_ID, resp. PARENT_PHYS_ID you should use a surrogate key, preferable generated from a sequence. In this case there is no reason (and no possibility) to change them ever.

The root Id you could get with this query:

SELECT p.*, CONNECT_BY_ROOT PHYS_ID AS ROOT_ID
FROM UNIQUE_PHYSICIAN p
START WITH PARENT_PHYS_ID IS NULL 
CONNECT BY PRIOR PHYS_ID = PARENT_PHYS_ID;