title: How to escape ":" in Oracle dynamic SQL and also have bind variables?
body: <p>I'm trying to make the following a dynamic SQL, but <code>:</code> character is messing up -</p>
  
  <pre><code>alter session set events 'sql_trace [sql: asasasaass]';
  </code></pre>
  
  <p>Example:</p>
  
  <pre><code>declare
   l_trc_cmd   varchar2(500);
   l_sql_id    varchar2(500) := 'asasasaass';
  begin
    l_trc_cmd     := q'# alter session set events 'sql_trace [sql: :L_SQL_ID]' #';
    execute immediate l_trc_cmd using l_sql_id;
  end;
  /
  </code></pre>
  
  <p>Above fails with:</p>
  
  <pre><code>ERROR at line 1:
  ORA-01006: bind variable does not exist
  </code></pre>
  
  <hr>
  
  <p>One <code>:</code> is required as per syntax of the SQL, and another <code>:</code> is for bind variable. </p>
  
  <p>Any ideas on how to fix this other than concatenating the bind value?</p>
  
  <p>--
  Edited on April 4th at 5.10pm CST  to add following:</p>
  
  <p>Alter session is not DDL command. Below  is proof. </p>
  
  <pre><code>sqlplus+&gt; select * from t2;
  
           A
  ----------
           1
  
  1 row selected.
  
  sqlplus+&gt; insert into t2 values(2);
  
  1 row created.
  
  sqlplus+&gt; alter session set tracefile_identifier ="umappsperf1" statistics_level=all;
  
  Session altered.
  
  sqlplus+&gt; alter session set events 'sql_trace wait=true';
  
  Session altered.
  
  sqlplus+&gt; select * from t2;
  
           A
  ----------
           2
           1
  
  2 rows selected.
  
  sqlplus+&gt; rollback;
  
  Rollback complete.
  
  sqlplus+&gt; select * from t2;
  
           A
  ----------
           1
  
  1 row selected.
  </code></pre>