title: Oracle SQL: adding the same sequence number to the rows of a query
body: <p>I am sending to a downstream application events and I need in each event a sequence number, as a control number that I don't have gaps, I don't miss sending events. 
  What I am trying to achieve is having a db sequence, to have assigned to the results of a query the same sequence number. I don't want to use a procedure, function, etc, only some SQL.</p>
  
  <p>For example I need a query result like this:</p>
  
  <pre>
  col1row1  col2row1 seq1
  col1row2  col2row2 seq1
  col1row3  col2row3 seq1
  col1row4  col2row4 seq1
  </pre>
  
  <p>The problems I found is that sequence have restrictions is queries or that I have different values for seq1.</p>
  
  <p>I tried this:</p>
  
  <pre><code>SELECT t.*, ROWNUM, 
  CASE ROWNUM
    WHEN 1 THEN MY_SEQ.NEXTVAL
    ELSE MY_SEQ.CURRVAL
  END as event_seq
  from my_table t
  </code></pre>
  
  <p>or </p>
  
  <pre><code>SELECT t.*, ROWNUM, decode(rownum, 1, MY_SEQ.NEXTVAL, MY_SEQ.CURRVAL) from my_table t
  </code></pre>
  
  <p>and the sequence is defined:</p>
  
  <pre><code>CREATE SEQUENCE MY_SEQ MINVALUE 1 MAXVALUE 999999999999999999999999999 
  INCREMENT BY 1 START WITH 1 NOCACHE NOORDER NOCYCLE ;
  </code></pre>