title: Modify PL/SQL statement strings in C++
body: <p>This is my use case: Input is a string representing an <strong>Oracle PL/SQL statement</strong> of arbitray complexity. We may assume it's a single statement (not a script).
  Now, several <strong>bits of this input string have to be rewritten</strong>. </p>
  
  <p>E.g. table names need to be prefixed, aggregate functions in the selection list that don't use a column alias should be assigned a default one:</p>
  
  <pre><code>SELECT SUM(ABS(x.value)), 
  TO_CHAR(y.ID,'111,111'),
  y.some_col
  FROM
  tableX x,
  (SELECT DISTINCT ID
  FROM tableZ z
  WHERE ID &gt; 10) y
  WHERE
  ...
  </code></pre>
  
  <p>becomes</p>
  
  <pre><code>SELECT SUM(ABS(x.value)) COL1, 
  TO_CHAR(y.ID,'111,111') COL2,
  y.some_col
  FROM
  pref.tableX x,
  (SELECT DISTINCT ID, some_col
  FROM pref.tableZ z
  WHERE ID &gt; 10) y
  WHERE
  ...
  </code></pre>
  
  <p><em>(Disclaimer: just to illustrate the issue, statement does not make sense)</em></p>
  
  <p>Since aggregate functions might be nested and subSELECTs are a b_tch, I dare not use regular expressions. Well, actually I did and achieved 80% of success, but I do need the remaining 20%.</p>
  
  <p>The right approach, I presume, is to use grammars and parsers.
  I fiddled around with c++ ANTLR2 (although I do not know much about grammars and parsing with the help of such). I do not see an easy way to get the SQL bits:</p>
  
  <pre><code>list&lt;string&gt; *ssel = theAST.getSubSelectList(); // fantasy land
  </code></pre>
  
  <p>Could anybody maybe provide some pointers on how "parsing professionals" would pursue this issue?
  EDIT: I am using <strong>Oracle 9i</strong>.</p>