/****************************************************************************
*
* Filename         - $Workfile:   make_sequence_no.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, 1998
*
*****************************************************************************/
/****************************************************************************
* @(#)$Workfile:   make_sequence_no.sql  $  $Revision:   1.3  $
*
* 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/procedures/make_sequence_no.svl  $
* 
*    Rev 1.3   20 Sep 1999 14:41:40   tagtrak
*  
* 
*    Rev 1.2   08 Apr 1999 15:23:06   tagtrak
* OR: 13206
* CR:  
* REV:
* Andrew Walker
* (branch build revision copied to trunk.)
* Neil Bishop
* 
*    Rev 1.1.1.0   25 Feb 1999 15:24:48   tagtrak
* OR: 13206
* CR:  
* REV:
* Andrew Walker
* 
*    Rev 1.1   25 Sep 1998 10:04:24   tagtrak
* OR: 12484
* CR: 12484
* REV:
* Merged Vienna (0.3.1E) and Core Product (0.2.5E) -
* branch ATS revision moved to trunk.
* Andrew Walker
* 
*    Rev 1.0.1.0   18 Aug 1998 09:44:24   tagtrak
* OR: 12484
* CR: 12484
* REV:
* Merging Vienna (0.3.1E) and Core Product (0.2.5E).
* Andrew Walker
* 
*    Rev 1.0   13 Jul 1998 13:23:54   tagtrak
* OR: 12217
* CR: 12217
* REV:
* Support duplicate sequence nos.
* Peter Dawson
* 
*
****************************************************************************/
                     
PROMPT CREATE OR REPLACE PROCEDURE make_sequence_no
                     
CREATE OR REPLACE PROCEDURE make_sequence_no
(
   booked_fid IN     pax.booked_flight_id%TYPE,
   seqno      IN OUT pax.pax_sequence_no%TYPE
)
AS
BEGIN

   /* Select the maximum sequence number that has been allocated
    * by TagTrak from the pax table, convert it to an int and
    * increment it. */

   SELECT (MAX(pax_sequence_no))
     INTO seqno
     FROM pax
    WHERE booked_flight_id = booked_fid
      AND pax_sequence_no > 100000;

   IF seqno IS NULL THEN
      seqno := 100000;
   END IF;

   seqno := seqno + 1;

END make_sequence_no;
/
