Hi,
I am new to PL/SQL and need some help. I have a following trigger and can't figure out how to rollback the transaction in the following code:

Code:
BEGIN	    
	    OPEN CUR_V1;
	    LOOP
	       FETCH CUR_V1 INTO VAR_1, VAR_2, VAR_3;
	       EXIT WHEN CUR_V1%NOTFOUND;
		   IF VAR_1 IS NOT NULL AND VAR_2 IS NOT NULL AND VAR_3 IS NOT NULL THEN
	              INSERT INTO IN_OUT_STAGE(ID,VAR_15,VAR_10,PS,LN) VALUES(SEQUENCE_TEST.NEXTVAL,:NEW.VAR_15,VAR_1,VAR_2,VAR_3);
		   ELSE
			  V_FLAG := TRUE;
			  ROLLBACK;
			  EXIT;
		   END IF;	    END LOOP;
		CLOSE CUR_V1;
		
		IF V_FLAG = TRUE THEN
		   RAISE E_EXCEPTION_V3;
		END IF;
How do I Rollback the whole transaction if some of the records in the cursor don't pass the condition for inserting. How do I make all the records to be committed only if all the records in the CURSOR meets the conditions. If any record fails the condition want to rollback all the transaction and get rid of the inserted records.

How do I make sure if the cursor contains atleast one record before I start looping.

Following is Trigger code. Any tips appreciated to make it more cleaner and better exception handling in it:

Code:
CREATE OR REPLACE TRIGGER DBSYSUSR.TSTTRG 
AFTER INSERT OR UPDATE ON STARTTBL
FOR EACH ROW
DECLARE 
    VAR_1 V_VIEW.V_V1%TYPE; 
    VAR_2 V_VIEW.V_V2%TYPE; 
    VAR_3 V_VIEW.V_V3%TYPE; 
    V_CNT NUMBER;
    V_E_NUMB NUMBER;
    V_E_MESSAGE VARCHAR2(100);
    V_TEMP VARCHAR2(20);
    V_FLAG BOOLEAN := FALSE;
    E_EXCEPTION1 EXCEPTION;
    E_EXCEPTION2 EXCEPTION;
    E_EXCEPTION_V3 EXCEPTION;
		
    CURSOR CUR_V1 IS 
      SELECT CD.V_V1, 
             CD.V_V2,
	     CD.V_V3
      FROM V_VIEW CD
      WHERE CD.V_V1 = :NEW.VAR_10;   
BEGIN
    BEGIN
	    V_CNT := 0;
	    IF :NEW.VAR_10 IS NOT NULL THEN
	       V_TEMP := TRIM(UPPER(:NEW.VAR_10));
	       SELECT COUNT(*) INTO V_CNT
	       FROM CHECK_LIST
	       WHERE UPPER(VAR_10_VALUE) = V_TEMP; 
	    ELSE
		RAISE E_EXCEPTION1;
	    END IF;
		
	    IF V_CNT = 0 THEN
	       RAISE E_EXCEPTION2;
	    END IF;
		
	EXCEPTION
	    WHEN E_EXCEPTION1
        THEN
	    RAISE E_EXCEPTION1;
			
	WHEN E_EXCEPTION2
        THEN
	    RAISE E_EXCEPTION2;
		
	WHEN OTHERS
	THEN		    
	    V_E_NUMB := SQLCODE;
            V_E_MESSAGE := SUBSTR(SQLERRM, 1, 100);
	    RAISE_APPLICATION_ERROR(-20000, 'ERROR IN TSTTRG - ' || V_E_NUMB || '-' || V_E_MESSAGE);
    END;
	
	BEGIN	    
	    OPEN CUR_V1;
	    LOOP
	       FETCH CUR_V1 INTO VAR_1, VAR_2, VAR_3;
	       EXIT WHEN CUR_V1%NOTFOUND;
		   IF VAR_1 IS NOT NULL AND VAR_2 IS NOT NULL AND VAR_3 IS NOT NULL THEN
	              INSERT INTO IN_OUT_STAGE(ID,VAR_15,VAR_10,PS,LN) VALUES(SEQUENCE_TEST.NEXTVAL,:NEW.VAR_15,VAR_1,VAR_2,VAR_3);
		   ELSE
			  V_FLAG := TRUE;
			  ROLLBACK;
			  EXIT;
		   END IF;
	    END LOOP;
		CLOSE CUR_V1;
		
		IF V_FLAG = TRUE THEN
		   RAISE E_EXCEPTION_V3;
		END IF;
	EXCEPTION
	    WHEN E_EXCEPTION_V3
		THEN
		    RAISE E_EXCEPTION_V3;
			
		WHEN OTHERS
		THEN
		    V_E_NUMB := SQLCODE;
                    V_E_MESSAGE := SUBSTR(SQLERRM, 1, 100);
		    RAISE_APPLICATION_ERROR(-20000, 'ERROR IN TSTTRG - ' || V_E_NUMB || '-' || V_E_MESSAGE);
	END;
EXCEPTION
  WHEN E_EXCEPTION1
  THEN
	 INSERT INTO CCA_LOG(LOG) VALUES('THERE IS NO VAR_10 ' || :NEW.VAR_15 || ' - ' || :NEW.VARIABLE_LN);
  
  WHEN E_EXCEPTION2
  THEN
	 INSERT INTO CCA_LOG(LOG) VALUES('THERE IS NO COUNT ' || :NEW.VAR_15 || ' - ' || :NEW.VARIABLE_LN);
      
  WHEN E_EXCEPTION_V3
  THEN
	 INSERT INTO CCA_LOG(LOG) VALUES('THERE IS NO VIEW DATA ' || :NEW.VAR_15 || ' - ' || :NEW.VARIABLE_LN);
   
  WHEN OTHERS
  THEN
      V_E_NUMB := SQLCODE;
      V_E_MESSAGE := SUBSTR(SQLERRM, 1, 100);
      DBMS_OUTPUT.PUT_LINE('ERROR IN TRG -' || V_E_NUMB || '-' || V_E_MESSAGE);
END TSTTRG;

/
/
Any help is appreciated. Thanks