title: Oracle creating sequences with execute immediate
body: <p>This might have already been asked but I am not able to resolve it, so posting again. </p>
  
  <p>I need to create an oracle sequence with the start value coming from a variable. So obviously I need to use execute immediate for the same within a pl/sql block. </p>
  
  <p>I used the following PL/SQL block to create the sequence:</p>
  
  <pre><code>declare nl_seqmax NUMBER :=0; 
  BEGIN 
    SELECT 1000000009 
        into nl_seqmax 
    from dual; 
    if nl_seqmax &gt; 0 THEN 
        execute immediate 'CREATE SEQUENCE my_seq INCREMENT BY 1 START WITH '||nl_seqmax || ' MAXVALUE 4000000000 CACHE 20 ORDER'; 
    end if; 
  end; 
  / 
  
  PL/SQL procedure successfully completed.
  </code></pre>
  
  <p>But later when referencing this sequence, I see that it throws 942 error. </p>
  
  <pre><code>SQL&gt; AUDIT GRANT ON my_seq  BY ACCESS WHENEVER SUCCESSFUL;
  
  ERROR at line 1:
  ORA-00942: table or view does not exist
  </code></pre>
  
  <p>Any idea on this ? Should all the references to sequence also should use dynamic sql ? </p>