/*============================================================================*
 |                 Copyright (c) 2008 Applaud Solutions UK Ltd                |
 |                             All rights reserved                            |
 *===========================================================================*/

SET FEEDBACK OFF
SET VERIFY OFF
SET SERVEROUT ON

DECLARE

  l_max_sessionid 	number 			:= 0;
  l_sql        		varchar2(400);
  

BEGIN

  --
  -- Retrieve max session id using dynamic SQL
  -- in case the table does not yet exist.
  --
  l_sql := ' select max(session_id) ' 
		|| ' from xxas_com_applied_patches ';

  EXECUTE IMMEDIATE l_sql INTO l_max_sessionid;
  
  IF l_max_sessionid IS NULL
  THEN
  l_max_sessionid := 0;
  dbms_output.put_line(l_max_sessionid);

  ELSE
  
  dbms_output.put_line(l_max_sessionid);
  END IF;
  
EXCEPTION

  WHEN others THEN
    --
    -- Table does not exist, invalid Oracle apps release
    --
    dbms_output.put_line(l_max_sessionid);

END;
/
COMMIT;
EXIT;