CREATE OR REPLACE TRIGGER "ATUPRODNIVANTE"
BEFORE INSERT ON PRODUTO FOR EACH ROW
DECLARE
    V_CDPRODNIVANTE PRODUTO.CDPRODUTO%TYPE;
BEGIN
IF INSERTING THEN
SELECT SUBSTR(:NEW.CDARVPROD, 0, (SELECT SUM(LENGTH(REGEXP_SUBSTR(CDPICTPROD,'[^.]+', 1, LEVEL))) AS TAMMASCARA FROM PARAMGERAL
      WHERE ROWNUM <= ( :NEW.CDNVPRODUTO  -1)
      CONNECT BY REGEXP_SUBSTR(CDPICTPROD, '[^.]+', 1, LEVEL) IS NOT NULL)) 
      INTO V_CDPRODNIVANTE
      FROM DUAL;
      
:NEW.CDPRODNIVANTE := V_CDPRODNIVANTE;
END IF;
END;
/