-1

为什么我的代码会出现此错误?这在 SQuirreL 中运行,但我"ORA-00933: SQL command not properly ended"在 Groovy 中运行。啊啊啊!请帮助我,您的知识非常感谢和垂涎。当我将输出写入文件时发生错误。如何在写作前选择正确的表格?

产生错误的是结束行:

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")
}
4

2 回答 2

1

给你!

import groovy.sql.Sql

def db = Sql.newInstance(
    'jdbc:oracle:thin:@1X.XX.XXX.XXX:1521:ORCL',
    'XXXXXX', 'XXXXXX', 'oracle.jdbc.pool.OracleDataSource')

def sql = """
SELECT * FROM
(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)
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:/Output/' + dts + ' EXPEDITE_MOPS.xls')
file.write("")
db.eachRow(sql) {
    file.append(it.MOPID + "\t" + it.TYPE + "\n")
}
于 2013-06-18T16:43:35.817 回答
0

后面需要一个分号DROP TABLE TEMPXMOP24

于 2013-06-11T17:15:01.210 回答