title: How to store SQL result in a variable and parse the result to identify a possible pattern?
body: <p>The query below </p>
  
  <pre><code>INSERT INTO temp 
  SELECT esd, 
         'E' 
  FROM   test_data_sovlp 
  WHERE  esd IS NOT NULL 
  UNION ALL 
  SELECT td, 
         CASE is_db 
           WHEN 0 THEN 'S' 
           WHEN 1 THEN 'H' 
         END AS FLAG 
  FROM   test_data_sovlp 
  WHERE  td IS NOT NULL 
  </code></pre>
  
  <p>return the following data:</p>
  
  <pre><code>|----------|----------|
  |  DT      |  FLAG    |
  |----------|----------|
  |  10      |  E       |
  |  20      |  H       |
  |  30      |  E       |
  |  40      |  E       |
  |  50      |  E       |
  |  60      |  S       |
  |  70      |  H       |
  |  75      |  E       |
  |  80      |  H       |
  |  100     |  H       |
  |----------|----------|
  </code></pre>
  
  <p>when run against this table:</p>
  
  <pre><code>|----------|----------|----------|----------|----------|
  |    ID    |   ESD    |  TD      |   IS_DB  | TEST_SET |
  |----------|----------|----------|----------|----------|
  |    1     |  10      |  20      |    1     |    2     |
  |    2     |  30      |  (null)  |    1     |    2     |
  |    3     |  40      |  (null)  |    1     |    2     |
  |    4     |  50      |  60      |    0     |    2     |
  |    5     |  (null)  |  70      |    1     |    2     |
  |    6     |  75      |  100     |    1     |    2     |
  |    7     |  (null)  |  80      |    1     |    2     |
  |----------|----------|----------|----------|----------|
  </code></pre>
  
  <p><strong><em>Note</em></strong>: See the demo <a href="http://sqlfiddle.com/#!4/1415f/2" rel="nofollow noreferrer">here</a> or my previous post <a href="https://stackoverflow.com/questions/50432956/oracle-stored-procedure-and-cursor">here</a> for more details.</p>
  
  <p>What I'm interested in is to concatenate the <code>FLAG</code> value return by the query above, in the <code>DT</code> order.</p>
  
  <p>So for the query above, the concatenation (let's call it <code>q_result</code>) value is: <code>q_result = EHEEESEHH</code>.</p>
  
  <p>I want then to parse then <code>q_result</code> by block of 2 characters to detect the possible presence of any of the following sequence:</p>
  
  <pre><code>HH      EE      HS      SE
  </code></pre>
  
  <p>During the parse, if a pattern match anywhere in <code>q_result</code>, the proc I would like to write must return <code>0</code>.
  If no pattern match then the proc must return <code>1</code>.</p>
  
  <p><strong>Question</strong></p>
  
  <p>How can this be done ?</p>