title: mule executing query based on condition
body: <p>My query goes here, what option I need to select to run as mule application. </p>
  
  <pre><code> &lt;http:inbound-endpoint exchange-pattern="request-response"  host="myhost" port="${port}" path="offcycle" doc:name="HTTP"/&gt;
          &lt;set-variable variableName="companies" value="${companies.torun}" doc:name="Variable"/&gt;
          &lt;db:insert config-ref="hrlites_Configuration" doc:name="Database" &gt;
              &lt;db:dynamic-query&gt;
  insert into PAYRNUM (PAYGROUP,T2_PAYROLL_NUM,SEPCHK,NAME....)
  
          select T2_SOURCE_COMPANY,T2_PAYGROUP_TYPE,...
          from   (
          SELECT T2_SOURCE_COMPANY,T2_PAYGROUP_TYPE,PAY_END_DT,...
          FROM   CHK_STG2
          WHERE  COMPANY = #[flowVars.companies]
            AND  T2_PAYGROUP_TYPE = 'ZZ'
            AND  PAY_END_DT =  '30/JUN/2013'
          ORDER BY PAY_END_DT,
                CASE WHEN T2_INVOICE_NBR LIKE 'IN%' then 1
                     WHEN T2_INVOICE_NBR LIKE 'CM%' then 2                   
                     ELSE 3
                END
          ) a,
          (
          select t2_invoice_nbr, OFF_CYCLE, CASE When b.OFF_CYCLE ='N' THEN 0
                      ELSE rownum
                      END as T2_PAYROLL_NUM
          from   (
                  select distinct t2_invoice_nbr, OFF_CYCLE
                  from   (
                          SELECT T2_INVOICE_NBR,...
                          FROM   PS_T2_INV_CHK_STG2
                          WHERE  COMPANY = #[flowVars.companies]
                            AND  T2_PAYGROUP_TYPE = 'ZZ'
                            AND  PAY_END_DT =  '30/JUN/2013'
                          ORDER BY PAY_END_DT,
                              CASE WHEN T2_INVOICE_NBR LIKE 'IN%' then 1
                                    WHEN T2_INVOICE_NBR LIKE 'CM%' then 2                                 
                                    ELSE 3
                              END
                        )
                 ) b
          ) bb
      where a.t2_invoice_nbr = bb.t2_invoice_nbr      
      ORDER BY PAY_END_DT,
          CASE WHEN T2_INVOICE_NBR LIKE 'IN%' then 1            
               ELSE 5
          END;
          &lt;/db:dynamic-query&gt;
          &lt;/db:insert&gt;        
      &lt;/flow&gt;
  </code></pre>
  
  <p>1) If run the query, it executes fine in db. but If i run in mule flow I am getting following error:</p>
  
  <pre><code>2015-01-28 17:18:48 ERROR DefaultMessagingExceptionStrategy:337 - 
  ********************************************************************************
  Message               : ORA-00911: invalid character
   (java.sql.SQLSyntaxErrorException). Message payload is of type: String
  Type                  : org.mule.api.MessagingException
  Code                  : MULE_ERROR--2
  Payload               : /offcycle
  SQL Code              : 911
  JavaDoc               : http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html
  SQL State             : 42000
  ********************************************************************************
  Exception stack is:
  1. ORA-00911: invalid character
  (SQL Code: 911, SQL State: + 42000) (java.sql.SQLSyntaxErrorException)
    oracle.jdbc.driver.SQLStateMapping:91 (null)
  2. ORA-00911: invalid character
   (java.sql.SQLSyntaxErrorException). Message payload is of type: String (org.mule.api.MessagingException)
    org.mule.module.db.internal.processor.AbstractDbMessageProcessor:81
  ********************************************************************************
  Root Exception stack trace:
  java.sql.SQLSyntaxErrorException: ORA-00911: invalid character
  </code></pre>
  
  <p>I have selected type as  parameter instead of Dynamic, but no use.</p>
  
  <p>2) How to display the executed query in console, so that I will come to know the parameter passed and final query.</p>