/*****************************************************************************
*
* Filename         - $Workfile:   get_carrier_code3.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 Stored Procedure
*
* Language         - Oracle SQL*Plus script
*
* Classification   - Commercial In Confidence
*
*          (c) Ultra Electronics Limited, 1997
*
*****************************************************************************/
/****************************************************************************
* @(#)$Workfile:   get_carrier_code3.sql  $  $Revision:   1.4  $
*
* 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:   /shared/pvcs/tagtarch/db_ora/db/source/live/procedures/get_carrier_code3.sqv  $
* 
*    Rev 1.4   02 Apr 1998 19:35:10   tagtrak
* OR:
* CR:
* REV:
* Initial Issue
* See label for concession
* 
*    Rev 1.3   15 Jan 1998 12:12:44   tagtrak
* OR: OR11101, TN13, TN15
* CR:
* REV:
* Phase 2C to Phase 3 upgrade plus code review actions and resolving some technical isses.
* 
*    Rev 1.2   24 Oct 1997 11:10:26   tagtrak
* Added PVCS header information
*
****************************************************************************/
PROMPT create or replace procedure get_carrier_code3

create or replace procedure get_carrier_code3 (
	p_alpha_code   in  char,
	ret_bar_code   out char,
	used_default   out number
)
as
 
	found boolean := TRUE;

begin

	/*
	 * - Initialise Variable
	 * - Select the bar_code from the carrier_lookup table where the
	 *   alpha code is equal to the alpha_code passed in as a parameter.
	 *   IF no data is found the set the found variable to FALSE.
	 * - IF the found variable is false then
	 *   initialise the used_default variable
	 *   Select the value from the db_config table where the db_item is equal
	 *   to 'def_carr_des'.  If no data is found then set the values of the
	 *   variables.
	 */

	used_default := 0;
 
  /*
	 * Attempt to get the carrier bar code.
	 */

	begin
		select
			bar_code
		into
			ret_bar_code
		from
			carrier_lookup
		where
			alpha_code = p_alpha_code;

		exception
			when NO_DATA_FOUND then
				found := FALSE;
	end;
	 
	/*
	 * If there isn't one use the default value.
	 */

  if ( not found ) then
    used_default := 1;

		begin
			select
				rpad(db_value,3)
			into
				ret_bar_code
			from
				db_config
			where
				db_item = 'def_carr_des';

			exception
				when NO_DATA_FOUND then
					ret_bar_code := '';
					used_default := 0;
		end;
	end if;
	 
end get_carrier_code3;
/
