/* $Id$ */
/*============================================================================*
 |                 Copyright (c) 2018 Applaud Solutions UK Ltd                |
 |                             All rights reserved                            |
 *===========================================================================*/

SET VERIFY OFF
SET FEEDBACK OFF
WHENEVER OSERROR  EXIT FAILURE ROLLBACK
WHENEVER SQLERROR EXIT FAILURE ROLLBACK

DECLARE

  l_sql              varchar2(32767);
  e_tbl_exists       EXCEPTION;
  PRAGMA exception_init(e_tbl_exists, -00955);
  e_col_exists       EXCEPTION;
  PRAGMA exception_init(e_col_exists, -01430);

BEGIN

  l_sql :=
    'CREATE TABLE XXAS_COM_PRODUCT_USERS
      (user_id        number       NOT NULL
      ,prod_key       varchar2(30) NOT NULL
      ,status         raw(255)     NOT NULL
      ,CONSTRAINT XXAS_COM_PRODUCT_USERS_PK PRIMARY KEY(user_id, prod_key))';
  EXECUTE IMMEDIATE l_sql;
  
  l_sql := 'GRANT ALL ON XXAS_COM_PRODUCT_USERS TO &1 WITH GRANT OPTION';
  EXECUTE IMMEDIATE l_sql;

EXCEPTION

  WHEN e_tbl_exists THEN
    null;
  
END;
/

COMMIT;
EXIT;
