Question : Trigger errors

CREATE OR REPLACE TRIGGER insert_model_trigger
INSTEAD OF INSERT ON XXCZ_VA_BETTIS_ELECTRIC_DTL_V
REFERENCING NEW AS N
FOR EACH ROW
DECLARE
         v_row_count_1 NUMBER;
         v_row_count_2 NUMBER;
BEGIN
       IF INSERTING THEN
             SELECT COUNT(*)
       INTO v_row_count_1
       FROM XXCZ_VA_BETTIS_MODEL_INFO
       WHERE MODEL_SIZE = :N.MODEL_SIZE AND OPERATING_SPEED = :N.OPERATING_SPEED AND ACTIVE_FLAG = :N.ACTIVE_FLAG;
--       DBMS_OUTPUT.PUT_LINE('Rows Counted in First Table : '||v_row_count_1);
      
       SELECT COUNT(*)
       INTO v_row_count_2
       FROM XXCZ_VA_VOLTAGES
       WHERE VOLTAGE_ID = :N.VOLTAGE_ID AND ACTIVE_FLAG = :N.ACTIVE_FLAG;
--       DBMS_OUTPUT.PUT_LINE('Rows Counted in Second Table : '||v_row_count_2);
      
       IF v_row_count_1 = 0 AND v_row_count_2 = 0 THEN
             INSERT INTO XXCZ_VA_BETTIS_MODEL_INFO(MODEL_SERIES, MODEL_SIZE, MODEL_TORQUE, OPERATING_SPEED, ENCLOSURE_RATING,
                                                                       DUTY_CYCLE, SPRING_RETURN, APPLICATION_TYPE, HIGH_RESOLUTION_ALLOWED,
                                                                    HAND_WHEEL_ALLOWED, VISUAL_INDICATION_ALLOWED, MULTI_TURN_ALLOWED, MOUNTING_CONFIG,
                                                                    CONTROL_RELAY_ALLOWED, NUM_AUX_SWITCH_ALLOWED, BI_DIR_TRAVEL_ALLOWED, EXT_MOTOR_PROTECT_ALLOWED,
                                                                    ACTIVE_FLAG, CREATED_BY, CREATION_DATE, LAST_UPDATED_BY, LAST_UPDATE_DATE, LAST_UPDATE_LOGIN)
            VALUES(:N.MODEL_SERIES, :N.MODEL_SIZE, :N.MODEL_TORQUE, :N.OPERATING_SPEED, :N.ENCLOSURE_RATING,
                     :N.DUTY_CYCLE, :N.SPRING_RETURN, :N.APPLICATION_TYPE, :N.HIGH_RESOLUTION_ALLOWED,
                     :N.HAND_WHEEL_ALLOWED, :N.VISUAL_INDICATION_ALLOWED, :N.MULTI_TURN_ALLOWED, :N.MOUNTING_CONFIG,
                     :N.CONTROL_RELAY_ALLOWED, :N.NUM_AUX_SWITCH_ALLOWED, :N.BI_DIR_TRAVEL_ALLOWED, :N.EXT_MOTOR_PROTECT_ALLOWED,
                     :N.ACTIVE_FLAG,'',SYSDATE,'',SYSDATE,'');
            
            INSERT INTO XXCZ_VA_VOLTAGES (VOLTAGE_ID, VOLTAGE_VALUE, VOLTAGE_UNITS, ACTIVE_FLAG, CREATED_BY, CREATION_DATE, LAST_UPDATED_BY, LAST_UPDATE_DATE, LAST_UPDATE_LOGIN)
            VALUES(:N.VOLTAGE_ID, :N.VOLTAGE_VALUE, :N.VOLTAGE_UNITS, :N.ACTIVE_FLAG, '', SYSDATE, '', SYSDATE, '');
             
            INSERT INTO XXCZ_VA_BETTIS_VOLTAGES (MODEL_SIZE, OPERATING_SPEED, VOLTAGE_ID, ACTIVE_FLAG, CREATED_BY, CREATION_DATE, LAST_UPDATED_BY, LAST_UPDATE_DATE, LAST_UPDATE_LOGIN)
            VALUES(:N.MODEL_SIZE, :N.OPERATING_SPEED, :N.VOLTAGE_ID, :N.ACTIVE_FLAG, '', SYSDATE, '', SYSDATE, '');
       ELSIF v_row_count_1 = 0 AND v_row_count_2 = 1 THEN
             INSERT INTO XXCZ_VA_BETTIS_MODEL_INFO(MODEL_SIZE, OPERATING_SPEED, ACTIVE_FLAG, CREATED_BY, CREATION_DATE, LAST_UPDATED_BY, LAST_UPDATE_DATE, LAST_UPDATE_LOGIN)
            VALUES(:N.MODEL_SIZE, :N.OPERATING_SPEED, :N.ACTIVE_FLAG, '', SYSDATE, '', SYSDATE, '');
            
            INSERT INTO XXCZ_VA_BETTIS_VOLTAGES (MODEL_SIZE, OPERATING_SPEED, VOLTAGE_ID, ACTIVE_FLAG, CREATED_BY, CREATION_DATE, LAST_UPDATED_BY, LAST_UPDATE_DATE, LAST_UPDATE_LOGIN)
            VALUES(:N.MODEL_SIZE, :N.OPERATING_SPEED, :N.VOLTAGE_ID, :N.ACTIVE_FLAG, '', SYSDATE, '', SYSDATE, '');
       ELSIF v_row_count_1 = 1 AND v_row_count_2 = 0 THEN
             INSERT INTO XXCZ_VA_VOLTAGES(VOLTAGE_ID, VOLTAGE_VALUE, VOLTAGE_UNITS, ACTIVE_FLAG, CREATED_BY, CREATION_DATE, LAST_UPDATED_BY, LAST_UPDATE_DATE, LAST_UPDATE_LOGIN)
            VALUES(:N.VOLTAGE_ID, :N.VOLTAGE_VALUE, :N.VOLTAGE_UNITS, :N.ACTIVE_FLAG, '', SYSDATE, '', SYSDATE, '');
            
            INSERT INTO XXCZ_VA_BETTIS_VOLTAGES (MODEL_SIZE, OPERATING_SPEED, VOLTAGE_ID, ACTIVE_FLAG, CREATED_BY, CREATION_DATE, LAST_UPDATED_BY, LAST_UPDATE_DATE, LAST_UPDATE_LOGIN)
            VALUES(:N.MODEL_SIZE, :N.OPERATING_SPEED, :N.VOLTAGE_ID, :N.ACTIVE_FLAG, '', SYSDATE, '', SYSDATE, '');
       ELSIF v_row_count_1 > 1 AND v_row_count_2 > 1 THEN
                DBMS_OUTPUT.PUT_LINE('RECORD ALREADY EXIST');
       END IF;
      END IF;
END;

When i run this trigger i am getting error like this.

PLS-00049: bad bind variable 'N.VOLTAGE_ID'

Please let me know what is the problem

Answer : Trigger errors

is voltage_id a column in your view?  is it spelled correctly?
Random Solutions  
 
programming4us programming4us