title: Oracle SQL - How to execute a query stored in a variable via command line
body: <p>I tried in many ways without success to execute the query stored in a variable:</p>
  <pre><code>Connected to Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 
  Connected as xxx@yyy
  
  SQL&gt; declare
    2  var v_SQL := 'SELECT * FROM DUAL';
    3  begin
    4  exec v_SQL;
    5  end;
    6  /
  
  SQL&gt; begin
    4  exec immediate 'SELECT * FROM DUAL';
    5  end;
    6  /
  
  SQL&gt; declare
    2  var v_SQL NVARCHAR := 'SELECT * FROM DUAL';
    3  begin
    4  exec immediate v_SQL;
    5  end;
    6  /
  </code></pre>
  <p>It throws generally the following error:</p>
  <blockquote>
  <p>ORA-06550: line 2, column 11:
  PLS-00103: Symbol &quot;NVARCHAR2&quot; encountered when one of the following is expected:</p>
  <pre><code>:= . ( @ % ; not null range default character
  </code></pre>
  <p>The symbol &quot;:=&quot; has been replaced by &quot;NVARCHAR2&quot; to continue.
  ORA-06550: line 5, column 6:
  PLS-00103: Symbol &quot;V_SQL&quot; encountered when one of the following is expected:</p>
  <pre><code>:= . ( @ % ;
  </code></pre>
  </blockquote>