Home

CREATE OR REPLACE should be used instead of CREATE

Rule description

  • CREATE OR REPLACE should be used instead of CREATE

 

Non-compliant Code Example

CREATE TRIGGER trgCustomerAdded  --Non compliant code (Only create is used)
BEFORE INSERT ON CUSTOMERS FOR EACH ROW
DECLARE
   PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
   INSERT INTO CUSTOMERS VALUES(:new.pFirstName, :new.pLastName);
   COMMIT;  -- allowed only in autonomous triggers
END;

Compliant Code Example

CREATE OR REPLACE TRIGGER trgCustomerAdded --Compliant code (Create OR Replace is used instead of only Create)
BEFORE INSERT ON CUSTOMERS FOR EACH ROW
DECLARE
   PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
   INSERT INTO CUSTOMERS VALUES(:new.pFirstName, :new.pLastName);
   COMMIT;  -- allowed only in autonomous triggers
END;
Visual Expert 2020
 VEPLSQLRULE40