обычный опыт в oracle - PullRequest
       3

обычный опыт в oracle

0 голосов
/ 25 марта 2020

У меня есть таблица с такими значениями столбцов.

ERROR - abc failed to load service request on {Date/Time} .The CIRCUIT is missing.    
ERROR - abc failed to load service request on {Date/Time}. The JOB_STREET_NAME is missing.    
ERROR - abc failed to load service request on {Date/Time}. The JOB_TOWN is missing.

Я хотел найти для части {Date / Time} в этом конкретном столбце в моем пакете oracle и заменить его на CURRENT_TIMESTAMP. .

Не могу найти ничего, что работает для меня. Я новичок в этом. Ищу предложения.

Ответы [ 2 ]

0 голосов
/ 26 марта 2020

Простая функция ЗАМЕНА, кажется, работает очень хорошо.

SQL> -- create an populate table
SQL> create table errmsg (msg_id number,
  2                       msg_txt varchar2(100)
  3                      )
  4  ;

Table created.

SQL> insert into errmsg values (1,'ERROR - abc failed to load service request on {Date/Time} .The CIRCUIT is missing.');

1 row created.

SQL> insert into errmsg values (2,'ERROR - abc failed to load service request on {Date/Time}. The JOB_STREET_NAME is missing.');

1 row created.

SQL> insert into errmsg values (3,'ERROR - abc failed to load service request on {Date/Time}. The JOB_TOWN is missing.');

1 row created.

SQL> commit;

Commit complete.

SQL> select * from errmsg;

    MSG_ID
----------
MSG_TXT
--------------------------------------------------------------------------------
         1
ERROR - abc failed to load service request on {Date/Time} .The CIRCUIT is missin
g.


ERROR - abc failed to load service request on {Date/Time} .The CIRCUIT is missin
g.

         2
ERROR - abc failed to load service request on {Date/Time}. The JOB_STREET_NAME i
s missing.

         3
ERROR - abc failed to load service request on {Date/Time}. The JOB_TOWN is missi
ng.


3 rows selected.

SQL> -- test the method
SQL> select replace(msg_txt,'{Date/Time}',to_char(sysdate,'dd-Mon-yyyy hh24:mi:ss')) logged_message
  2  from errmsg
  3  where msg_id=1;

LOGGED_MESSAGE
--------------------------------------------------------------------------------
ERROR - abc failed to load service request on 25-Mar-2020 16:16:39 .The CIRCUIT
is missing.


1 row selected.

SQL> --
SQL> select replace(msg_txt,'{Date/Time}',to_char(sysdate,'dd-Mon-yyyy hh24:mi:ss')) logged_message
  2  from errmsg
  3  where msg_id=2;

LOGGED_MESSAGE
--------------------------------------------------------------------------------
ERROR - abc failed to load service request on 25-Mar-2020 16:16:39. The JOB_STRE
ET_NAME is missing.


1 row selected.

SQL> --
SQL> select replace(msg_txt,'{Date/Time}',to_char(sysdate,'dd-Mon-yyyy hh24:mi:ss')) logged_message
  2  from errmsg
  3  where msg_id=3;

LOGGED_MESSAGE
--------------------------------------------------------------------------------
ERROR - abc failed to load service request on 25-Mar-2020 16:16:39. The JOB_TOWN
 is missing.


1 row selected.

SQL> --
SQL> -- drop the table
SQL> drop table errmsg purge;

Table dropped.

SQL> spool off
0 голосов
/ 25 марта 2020

Я думаю, что вы можете достичь этого, используя REGEXP_SUBSTR следующим образом:

SELECT 
    REGEXP_SUBSTR(YOUR_COL,'failed to load service request on(.+) \.',1,1,NULL,1) 
FROM YOUR_TABLE
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...