title: Groovy - ORA-00933: SQL command not properly ended
body: <p>Why am I getting this error from my code?  This runs in SQuirreL but I get the <code>"ORA-00933: SQL command not properly ended"</code> in Groovy. Arrrrrrgh!  Please help me, you knowledge is greatly appreciated and coveted. My error occurs when I write the output to file.  How do I select the correct table becore writing?</p>
  
  <p>It is the ending line(s) that produce the error:</p>
  
  <pre><code>file.write("")
  db.eachRow(sql) {
      file.append(it.MOPID + "\t" + it.TYPE + "\n")
  }
  
   import groovy.sql.Sql
  
  def db = Sql.newInstance(
      'jdbc:oracle:thin:@10.10.47.193:1521:ORCL',
      'reporter', 'r3p0rt3r', 'oracle.jdbc.pool.OracleDataSource')
  
  def sql = """
  
  DROP TABLE TEMPXMOP24
  
  CREATE TABLE TEMPXMOP24
  (
     MOPID VARCHAR2(12),
     TYPE VARCHAR2(200),
     MOPSTART DATE,
     MOPAPPROVEDTIME DATE,
     TIME_DIF VARCHAR2(45),
     TIME_ORDER NUMBER(10),
     FIXED_MOP VARCHAR2(12),
     MOP_HR VARCHAR2(2)
  );
  
  INSERT INTO TEMPXMOP24 (MOPID,TYPE,MOPSTART,MOPAPPROVEDTIME,TIME_DIF,TIME_ORDER,FIXED_MOP,MOP_HR)
  SELECT MOPACTIVITY.MOPID,
  MOPACTIVITY.MOPSERVICEIMPACTED "TYPE",
  MOPACTIVITY.MOPSTART,
  MOPACTIVITY.MOPAPPROVEDTIME,
  ROUND(MOPACTIVITY.MOPSTART -  MOPACTIVITY.MOPAPPROVEDTIME,2)||' days' "TIME_DIF",
  ROUND(MOPACTIVITY.MOPSTART -  MOPACTIVITY.MOPAPPROVEDTIME,0) "TIME_ORDER",
   (CASE 
    WHEN SUBSTR(MOPACTIVITY.MOPID, 7, 2) = '24' THEN SUBSTR(MOPACTIVITY.MOPID, 1, 6)||'00'||SUBSTR(MOPACTIVITY.MOPID, 9, 4)
    ELSE MOPACTIVITY.MOPID
   END ) FIXED_MOP,
  (CASE 
    WHEN SUBSTR(MOPACTIVITY.MOPID, 7, 2) = '24' THEN SUBSTR(MOPACTIVITY.MOPID, 7, 2)
    ELSE SUBSTR(MOPACTIVITY.MOPID, 7, 2)
   END ) MOP_HR 
  FROM MOPUSER.MOPACTIVITY
  WHERE MOPACTIVITY.MOPSTART -  MOPACTIVITY.MOPAPPROVEDTIME BETWEEN 0 and 14;
  
  SELECT * FROM TEMPXMOP24
  WHERE TRUNC(TO_DATE(FIXED_MOP, 'MMDDYYHH24MISS'))
    BETWEEN TRUNC(SYSDATE-90) AND TRUNC(SYSDATE)
  ORDER BY "TIME_ORDER"
  
  def date = new Date() 
  def dts = date.format("yyyy-MM-dd-HH-mm-ss") 
  File file = new File('C:/Documents and Settings/e0148840/Desktop/' + dts + ' Caries 14 Day and Out.xls')
  file.write("")
  db.eachRow(sql) {
      file.append(it.MOPID + "\t" + it.TYPE + "\n")
  }
  </code></pre>