Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8456535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:34:08+00:00 2026-06-10T12:34:08+00:00

Is there a workaround/better way to do this: I have a field (TEREMARKS) which

  • 0

Is there a workaround/better way to do this:

I have a field (TEREMARKS) which contains a long string and out of that string I need to get the times and names that I can find in there. I extract the time and name when I encounter this format: TE=<HH:MM>(<NAME>)

My problem is sometimes the format is not followed by the encoder which would throw the ORA-01722. I would have wanted my program to skip the erroneous record and return the ones that are OK. Would that be possible? Here are the scripts:

Create table:

CREATE TABLE HPACC.TE_ENTRY
(
  TENUMBER    VARCHAR2(20 BYTE)                 NOT NULL,
  TEREMARKS   VARCHAR2(100 BYTE),
  TEUPDATEBY  VARCHAR2(15 BYTE),
  TETRXDT     DATE
);

Insert Data:

Insert into HPACC.TE_ENTRY (TENUMBER, TEREMARKS, TEUPDATEBY, TETRXDT)
Values ('115118002', 'TE=10:03 CU ANTI SEIZZURE ', 'ME1', TO_DATE('08/24/2012 10:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into HPACC.TE_ENTRY (TENUMBER, TEREMARKS, TEUPDATEBY, TETRXDT)
Values ('1151180025 ', 'TE= 10:19 ON AND OFF FEVER', 'ME2', TO_DATE('08/24/2012 10:01:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into HPACC.TE_ENTRY (TENUMBER, TEREMARKS, TEUPDATEBY, TETRXDT)
Values ('1153053592', 'TE=10:40(DIANE)   PRE''EMP', 'ME1', TO_DATE('08/24/2012 10:05:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into HPACC.TE_ENTRY (TENUMBER, TEREMARKS, TEUPDATEBY, TETRXDT)
Values ('1157019820', 'TE=10:45(KRISTEN), CU,MONITORING,RASHE,FEVER LAST MONDAY  ', 'ME1', TO_DATE('08/24/2012 10:12:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into HPACC.TE_ENTRY (TENUMBER, TEREMARKS, TEUPDATEBY, TETRXDT)
Values ('1157019832', 'TE=11-:13 PRE EMP EXTRACTED BY:CAMILLA', 'ME3', TO_DATE('08/24/2012 10:15:00', 'MM/DD/YYYY HH24:MI:SS'));

My Query:

SELECT TO_CHAR(DECODE(ORIGTIME, '1', '13','2', '14','3', '15','4', '16',ORIGTIME),'FM00') ATIME
      , DONEBY
      , COUNT(TENUMBER) AS CTOTAL 
FROM ( 
SELECT TENUMBER
        , (CASE WHEN (INSTR(UPPER(TEREMARKS),'TE=',1,1) <> 0) 
                  AND (LENGTH(TRIM(TRANSLATE(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'TE=',1,1)+3,(INSTR(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'TE=',1,1)),':',1,1))-4)
   , ' +-.0123456789', ' '))) IS  NULL) 
     THEN TO_NUMBER(REPLACE(TO_CHAR(TO_NUMBER(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'TE=',1,1)+3,(INSTR(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'TE=',1,1)),':',1,1))-4)),'FM99'),'-')) 
   ELSE 0 END) AS ORIGTIME
 , (CASE WHEN (INSTR(UPPER(TEREMARKS),'(',1,1) <> 0) 
    AND (LENGTH(TRIM(TRANSLATE(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'(',1,1)+1,(INSTR(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'(',1,1)+1),')',1,1))-1), ' +-.0123456789', ' '))) IS NULL) 
   THEN SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'(',1,1)+1,(INSTR(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'(',1,1)+1),')',1,1))-1) 
  ELSE TEUPDATEBY END) AS DONEBY 
FROM HPACC.TE_ENTRY 
  Where TETRXDT BETWEEN TO_DATE('08-24-2012 10:00:00','MM-DD-YYYY HH24:MI:SS') AND TO_DATE('08-24-2012 10:59:59','MM-DD-YYYY HH24:MI:SS') 
GROUP BY TENUMBER, TEREMARKS, TEUPDATEBY 
UNION
SELECT TENUMBER
    , (CASE WHEN (INSTR(UPPER(TEREMARKS),'TE=',1,2) <> 0) 
     AND (LENGTH(TRIM(TRANSLATE(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'TE=',1,2)+3,(INSTR(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'TE=',1,2)),':',1,1))-4), ' +-.0123456789', ' '))) IS NULL) 
      THEN TO_NUMBER(REPLACE(TO_CHAR(TO_NUMBER(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'TE=',1,2)+3,(INSTR(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'TE=',1,2)),':',1,1))-4)),'FM99'),'-'))
   ELSE 0 END) AS ORIGTIME
 ,  (CASE WHEN (INSTR(UPPER(TEREMARKS),'(',1,2) <> 0) 
     AND (LENGTH(TRIM(TRANSLATE(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'(',1,2)+1,(INSTR(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'(',1,2)+1),')',1,1))-1), ' +-.0123456789', ' '))) IS NULL) 
 THEN SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'(',1,2)+1,(INSTR(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'(',1,2)+1),')',1,1))-1) 
Else 'NONE' END) AS DONEBY 
FROM HPACC.TE_ENTRY 
Where TETRXDT BETWEEN TO_DATE('08-24-2012 10:00:00','MM-DD-YYYY HH24:MI:SS') AND TO_DATE('08-24-2012 10:59:59','MM-DD-YYYY HH24:MI:SS') 
GROUP BY TENUMBER, TEREMARKS 
UNION  
SELECT TENUMBER
     , (CASE WHEN (INSTR(UPPER(TEREMARKS),'TE=',1,3) <> 0)
 AND (LENGTH(TRIM(TRANSLATE(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'TE=',1,3)+3, (INSTR(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'TE=',1,3)),':',1,1))-4), ' +-.0123456789', ' '))) IS NULL) 
THEN TO_NUMBER(REPLACE(TO_CHAR(TO_NUMBER(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'TE=',1,3)+3, (INSTR(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'TE=',1,3)),':',1,1))-4)),'FM99'),'-')) 
ELSE 0 END) AS ORIGTIME
, (CASE WHEN (INSTR(UPPER(TEREMARKS),'(',1,3) <> 0) 
  AND (LENGTH(TRIM(TRANSLATE(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'(',1,3)+1,(INSTR(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'(',1,3)+1),')',1,1))-1), ' +-.0123456789', ' '))) IS NULL) 
THEN SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'(',1,3)+1,(INSTR(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'(',1,3)+1),')',1,1))-1) 
Else 'NONE' END) AS DONEBY 
FROM HPACC.TE_ENTRY 
Where TETRXDT BETWEEN TO_DATE('08-24-2012 10:00:00','MM-DD-YYYY HH24:MI:SS') AND TO_DATE('08-24-2012 10:59:59','MM-DD-YYYY HH24:MI:SS') GROUP BY TENUMBER, TEREMARKS 
UNION 
SELECT TENUMBER
 , (CASE WHEN (INSTR(UPPER(TEREMARKS),'TE=',1,4) <> 0) 
 AND (LENGTH(TRIM(TRANSLATE(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'TE=',1,4)+3, (INSTR(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'TE=',1,4)),':',1,1))-4), ' +-.0123456789', ' '))) IS NULL) 
 THEN TO_NUMBER(REPLACE(TO_CHAR(TO_NUMBER(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'TE=',1,4)+3, (INSTR(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'TE=',1,4)),':',1,1))-4)),'FM99'),'-')) 
ELSE 0 END) AS ORIGTIME, 
(CASE WHEN (INSTR(UPPER(TEREMARKS),'(',1,4) <> 0)
 AND (LENGTH(TRIM(TRANSLATE(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'(',1,4)+1,(INSTR(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'(',1,4)+1),')',1,1))-1), ' +-.0123456789', ' '))) IS NULL) 
 THEN SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'(',1,4)+1,(INSTR(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'(',1,4)+1),')',1,1))-1) 
Else 'NONE' END) AS DONEBY 
FROM HPACC.TE_ENTRY
Where TETRXDT BETWEEN TO_DATE('08-24-2012 10:00:00','MM-DD-YYYY HH24:MI:SS') AND TO_DATE('08-24-2012 10:59:59','MM-DD-YYYY HH24:MI:SS')
GROUP BY TENUMBER, TEREMARKS 
UNION 
SELECT TENUMBER
, (CASE WHEN (INSTR(UPPER(TEREMARKS),'TE=',1,5) <> 0) 
AND (LENGTH(TRIM(TRANSLATE(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'TE=',1,5)+3,(INSTR(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'TE=',1,5)),':',1,1))-4), ' +-.0123456789', ' '))) IS NULL) 
 THEN TO_NUMBER(REPLACE(TO_CHAR(TO_NUMBER(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'TE=',1,5)+3,(INSTR(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'TE=',1,5)),':',1,1))-4)),'FM99'),'-'))
 ELSE 0 END) AS ORIGTIME
, (CASE WHEN (INSTR(UPPER(TEREMARKS),'(',1,5) <> 0) AND (LENGTH(TRIM(TRANSLATE(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'(',1,5)+1,(INSTR(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'(',1,5)+1),')',1,1))-1), ' +-.0123456789', ' '))) IS NULL) 
THEN 
 SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'(',1,5)+1,(INSTR(SUBSTR(TEREMARKS,INSTR(UPPER(TEREMARKS),'(',1,5)+1),')',1,1))-1) 
   Else 'NONE' END) AS DONEBY
FROM HPACC.TE_ENTRY Where TETRXDT BETWEEN TO_DATE('08-24-2012 10:00:00','MM-DD-YYYY HH24:MI:SS') AND TO_DATE('08-24-2012 10:59:59','MM-DD-YYYY HH24:MI:SS') 
GROUP BY TENUMBER, TEREMARKS
) 
Where ORIGTIME <> 0 
Group By ORIGTIME, DONEBY 
Order By TO_CHAR(TO_NUMBER(ATIME),'FM00') , DONEBY;

The last record (10:15) causes the error. How to bypass that one?
I also feel like my script is too verbose. Would appreciate your corrections, suggestions and examples. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T12:34:09+00:00Added an answer on June 10, 2026 at 12:34 pm

    As Alex commented this is obviously a task for regular expressions.

    Here’s one that will work with your current data.

    select regexp_substr( teremarks
                       , '^TE=[[:space:]]?[[:digit:]]{2}[[:print:]]?:[[:digit:]]{2}')
         , regexp_substr( teremarks
                       , '([(][[:alpha:]]+[)]|:[[:alpha:]]+$)')
    from te_entry
    

    This matches, from the beginning of the string, TE, followed by an =, then an optional space, two numbers an optional character, : then another two numbers.

    The seconds matches either ( followed by any number of letters followed by ), or : followed by any number of letters at the end of the line.

    Or, to get out just the time and name, removing all the extra stuff:

    with matched as (
     select regexp_substr( teremarks
                        , '^TE=[[:space:]]?[[:digit:]]{2}[[:print:]]?:[[:digit:]]{2}'
                           ) as time
          , regexp_substr( teremarks
                        , '([(][[:alpha:]]+[)]|:[[:alpha:]]+$)'
                            ) as name
       from te_entry
            )
    select regexp_replace( time
                        , '[^([:digit:]|:)]')
         , regexp_replace( name
                        , '[^[:alpha:]]')
    from matched
    

    Here’s a SQL Fiddle to demonstrate. Please also note that regular expressions are only available in Oracle 10g or later.

    I would just like to emphasise that while this will work on your current data it does not mean that it will work forever. There will always be more cases that you hadn’t thought of. If the results of this query are important you should change your table to include a column that has the date (not time) the measurements were taken and another column that has the name of the person taking it.

    This is the only way you can be certain that your data is correct.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a field with a custom attribute on it, that looks like this:
I have a form which, among the other controls, has a TextBox field that
Is there a workaround for Internet Explorer to implement the functionality offered by 'this'
Update: See the bottom of this question for a C# workaround. Hi there, Consider
I have a model, blog_posts which has a field published_at. I'd like to select
Is there a way to specify in type parameters that a parameter is the
Is there any workaround for the following 1 pixel to the left bug? <!DOCTYPE
Is there any workaround to allow actionscript3 write to file system without adobe air?
Is there any Workaround/Tool for renaming the Resource Keys from the resource file .
Is there a workaround to stop Update-FormatData complaining about a loaded file when the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.