我正在运行一个多表 SQL 调用,该调用启动到 file.write。该代码在 SQuirreL 甚至在 Groovy 中都可以工作,直到我到达 file.write("") 行(代码的最后 4 行)。我收到的第一条错误消息“因为:ORA-00911:无效字符”,其余的与它类似。
这是我认为错误所在的位置:
file.write("")
db.eachRow(sql) {
file.append(it.MOPID + "\t" + it.EOM + "\t" + it.Mopstart + "\n")
我认为我的代码的问题在于有不止一张桌子,而且在写东西的时候,有些东西已经被抬高了。非常感谢您的知识。
恭敬地~Corpa Loom <3
以下是完整的代码:
import groovy.sql.Sql
def db = Sql.newInstance(
'jdbc:oracle:thin:@XX.XX.XX.XXX:XXXX:ORCL',
'reporter', 'XXXXXXX', 'oracle.jdbc.XXXX.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:/OUTPUT/' +dts + ' Past Due CM Mops.xls')
file.write("")
db.eachRow(sql) {
file.append(it.MOPID + "\t" + it.TYPE + "\t" + it.MOPSTART + "\n")
}