--ABS-122346 / ABS-122414
--originally created by Script_09.00.05.19.sql
CREATE OR REPLACE PROCEDURE CREATE_A_DATABASESETTINGS AS
CREATESTMT VARCHAR2(5000);
INSERTSTMT VARCHAR2(5000);
LV_EXISTS NUMBER;
BEGIN
  LV_EXISTS := 0;
  SELECT COUNT(UT.TABLE_NAME)
  INTO LV_EXISTS
  FROM USER_TABLES UT
  WHERE UT.TABLE_NAME = 'A_DATABASESETTINGS';
  IF LV_EXISTS = 0 THEN
    BEGIN
      CREATESTMT := 'CREATE TABLE A_DATABASESETTINGS
(
  CODE                       VARCHAR2(3),
  LANCODE                    VARCHAR2(2),
  REFERENCEYEAR              NUMBER,
  REFERENCEWEEK              NUMBER,
  ABSHOMEPAGE                VARCHAR2(80),
  OVERALLUNIQUEGARMENTID     VARCHAR2(1 BYTE),
  LOCALE                     VARCHAR2(5),
  TIMEZONE                   VARCHAR2(40),
  MENUBASELANGUAGE           VARCHAR2(2) NOT NULL,
  DBLOGDIR                   VARCHAR2(60),
  PRINTLABELSDIRECTLY        VARCHAR2(1 BYTE) NOT NULL,
  LOGDBSESSIONAPPSERV        VARCHAR2(1 BYTE) NOT NULL,
  LOGDBSESSIONREPSERV        VARCHAR2(1 BYTE) NOT NULL,
  LOGSTACKTRACEAPPSERV       VARCHAR2(1 BYTE) NOT NULL,
  LOGSTACKTRACEREPSERV       VARCHAR2(1 BYTE) NOT NULL,
  ENVIRONMENT                VARCHAR2(15),
  MESSAGEATLOGIN             CLOB,
  TABLESPACENAME             VARCHAR2(40),
  DATATBLSPACENAME           VARCHAR2(40),
  OVERALLUNIQUERESIDENTIALID VARCHAR2(1) NOT NULL,
  NLS_TERRITORY              VARCHAR2(160),
  A_ACTION                   VARCHAR2(1) DEFAULT ''I'' NOT NULL,
  A_TIMESTAMP                DATE DEFAULT SYSDATE NOT NULL,
  A_CLIENT_IDENTIFIER        VARCHAR2(64)
)';
      INSERTSTMT := 'INSERT INTO A_DATABASESETTINGS
  (CODE, LANCODE, REFERENCEYEAR, REFERENCEWEEK, ABSHOMEPAGE, OVERALLUNIQUEGARMENTID, LOCALE,
   TIMEZONE, MENUBASELANGUAGE, DBLOGDIR, PRINTLABELSDIRECTLY, LOGDBSESSIONAPPSERV,
   LOGDBSESSIONREPSERV, LOGSTACKTRACEAPPSERV, LOGSTACKTRACEREPSERV, ENVIRONMENT, MESSAGEATLOGIN,
   TABLESPACENAME, DATATBLSPACENAME, OVERALLUNIQUERESIDENTIALID, NLS_TERRITORY)
  SELECT CODE, LANCODE, REFERENCEYEAR, REFERENCEWEEK, ABSHOMEPAGE, OVERALLUNIQUEGARMENTID, LOCALE,
         TIMEZONE, MENUBASELANGUAGE, DBLOGDIR, PRINTLABELSDIRECTLY, LOGDBSESSIONAPPSERV,
         LOGDBSESSIONREPSERV, LOGSTACKTRACEAPPSERV, LOGSTACKTRACEREPSERV, ENVIRONMENTNAME,
         MESSAGEATLOGIN, TABLESPACENAME, DATATBLSPACENAME, OVERALLUNIQUERESIDENTIALID, NLS_TERRITORY
  FROM   DATABASESETTINGS D
  WHERE NOT EXISTS (SELECT 1 FROM A_DATABASESETTINGS A
  WHERE A.CODE = D.CODE)';
      EXECUTE IMMEDIATE(CREATESTMT);
      EXECUTE IMMEDIATE(INSERTSTMT);
      COMMIT;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    END IF;
END CREATE_A_DATABASESETTINGS;
/
EXECUTE CREATE_A_DATABASESETTINGS;

DROP PROCEDURE CREATE_A_DATABASESETTINGS;