/*****************************************************************************
*
* Filename         - $Workfile:   carrier_subgroup_triggers.sql  $
*
*                     Name              Date      Version     CR Number
* Author           - See revision history below.
* Last Update      - See revision history below.
*
* Project Name     - TAGTRAK(Oracle Database)
*
* Source Code
* Identifier       - 0/3/300/8010/112
*
* Design Spec
* Section          - 
*
* Contents         -  Live Schema: triggers for error table
*
* Language         - Oracle SQL*Plus script
*
* Classification   - Commercial In Confidence
*
*          (c) Ultra Electronics Limited, 1997
*
*****************************************************************************/
/****************************************************************************
* @(#)$Workfile:   carrier_subgroup_triggers.sql  $  $Revision:   1.0  $
*
* Revision History
*
* Note that user tagtrak is many users. For these users the user
* name is entered as the last line in the change description.
*
* $Log:   /pvcsarch/db_ora/db/source/live/triggers/carrier_subgroup_triggers.svl  $
* 
*    Rev 1.0   06 Jun 2000 09:56:46   tagtrak
* Initial revision
* 
*
****************************************************************************/



create or replace trigger ti_carrier_subgroup
before insert on carrier_subgroup
for each row
declare
	numrows integer;
begin

	/*
	 * Disallow  flight number to overlap for one alpha_code
	 */
	 select count(*) into numrows from carrier_subgroup 
	 where :new.MIN_FLIGHT_NO >= MIN_FLIGHT_NO and
				 :new.MIN_FLIGHT_NO <= MAX_FLIGHT_NO and
				 :new.alpha_code = alpha_code ;
	
	if (numrows > 0) then
		 raise_application_error( -20039, 'flight number range invalid or overlap');
	end if;
	
	 select count(*) into numrows from carrier_subgroup 
	 where :new.MAX_FLIGHT_NO >= MIN_FLIGHT_NO and
				 :new.MAX_FLIGHT_NO <= MAX_FLIGHT_NO and
				 :new.alpha_code = alpha_code ;
	
	if (numrows > 0) then
		 raise_application_error( -20039, 'flight number range invalid or overlap');
	end if;
	
	if (:new.MAX_FLIGHT_NO < :new.MIN_FLIGHT_NO ) then
		 raise_application_error( -20039, 'flight number range invalid or overlap');
	end if;
	
end;
/
