/*
@C:\WEB_410\Sql\End_Conv\Oracle\0900_GERTRGO_UPDTHREADINFO.sql
*/

CREATE OR REPLACE TRIGGER UPDTHREADINFO
BEFORE INSERT ON BKGTHREAD
FOR EACH ROW
DECLARE
   V_CLIENT_INFO  VARCHAR2(64);
   V_SESSION_ID   VARCHAR2(24);
   V_CDOPERADOR   VARCHAR2(12);
BEGIN
   DBMS_APPLICATION_INFO.READ_CLIENT_INFO(V_CLIENT_INFO);
   V_SESSION_ID := DBMS_SESSION.UNIQUE_SESSION_ID;

   BEGIN
      SELECT CDOPERADOR
      INTO   V_CDOPERADOR
      FROM   OPERADOR
      WHERE  CDOPERADOR = SUBSTR(V_CLIENT_INFO,1,12);
  EXCEPTION
     WHEN NO_DATA_FOUND THEN
        V_CDOPERADOR := NULL;
  END;

   :NEW.DSIPADTHREAD := NVL(SUBSTR(TO_CHAR(ASCII(SUBSTR(V_CLIENT_INFO,53,1)))||'.'||TO_CHAR(ASCII(SUBSTR(V_CLIENT_INFO,54,1)))||'.'||TO_CHAR(ASCII(SUBSTR(V_CLIENT_INFO,55,1)))||'.'||TO_CHAR(ASCII(SUBSTR(V_CLIENT_INFO,56,1))),1,15), 'VIA BD');
   :NEW.DSHOSTTHREAD := NVL(SUBSTR(V_CLIENT_INFO,33,15), 'VIA BD');
   :NEW.DSAPPLTHREAD := TRIM(SUBSTR(V_CLIENT_INFO,48,5))||'.EXE';
   :NEW.CDOPERTHREAD := V_CDOPERADOR;
   :NEW.NRSIDTHREAD  := TO_NUMBER(SUBSTR(V_SESSION_ID,1,4),'XXXX');
   :NEW.NRAUDSIDTHRD := USERENV('SESSIONID');
END;
/

-- VERSAO --
BEGIN ATUVEROBJ('UPDTHREADINFO','6.05.xxx'); END;
/

