CREATE OR REPLACE TRIGGER mo_aufgabe_a
   BEFORE INSERT
   ON fabian_data
   FOR EACH ROW
   DECLARE
      tag_name VARCHAR2(255);
		v_authors INTEGER;
		v_artikel INTEGER;
		v_artikels INTEGER;
		v_issue INTEGER;
		anzahl INTEGER;
--		no_insert3 EXCEPTION;
	BEGIN
		SELECT name
		INTO tag_name
		FROM fabian_tag
		WHERE  id = :NEW.tagid;

		IF ( tag_name =  'author') THEN
			SELECT parent 
			INTO v_authors
			FROM fabian_ptr
			WHERE child = :NEW.tagid;
			
			SELECT COUNT (*)
			INTO anzahl
			FROM fabian_ptr
			WHERE parent = v_authors;
			
			IF (anzahl > 3) THEN
	     		SELECT parent
            INTO v_artikel
				FROM fabian_ptr
				WHERE child = v_authors;

 	     		SELECT parent
            INTO v_artikels
				FROM fabian_ptr
				WHERE child = v_artikel;

 	     		SELECT parent
            INTO v_issue
				FROM fabian_ptr
				WHERE child = v_artikels;
				
				DELETE FROM fabian_tag
				WHERE id = v_issue;
				
--				RAISE no_insert3;
			END IF;
     	END IF;
   END;
/
