ORA-00907:Python脚本中缺少右括号

时间:2016-06-08 16:59:32

标签: python sql oracle arcpy

我在ArcGIS的arcpy模块中使用python函数,名为“MakeQueryTable”。

http://pro.arcgis.com/en/pro-app/tool-reference/data-management/make-query-table.htm

基本上,它利用Oracle sql查询来构建表。我已经构建了一个脚本,我收到以下错误:

  

[ORA-00907:缺少右括号]

首先,我已经排队了,但似乎没有任何缺失的括号。再次,在换行并注释掉每一行并执行脚本以查看问题首次出现之后,似乎在我取消注释group by语句并删除LISTAGG语句之后发生。因此,当我删除group by语句并将LISAGG函数的行更改为["MTA.MTA_WORK_TYPE_ITEM_CODE.DESCRIPTION, ''Work_Type_Items']时,脚本将运行。当我允许group by语句时,脚本会抛出此错误。

不幸的是,我需要group by语句来生成我需要的表。 LISTAGG功能还依赖于分组才能正常运行。如果我要在Oracle SQL Developer中构建相同的查询,它将运行。我只是觉得我来这里看看有没有更好的SQL背景的人能否提出为什么会出现这个错误。

这是脚本:

tableList = ["MTA_SPATIAL.MTA_ACQUIRED_TENURE_SVW", "MTA.MTA_TENURE_EVENT_XREF", "MTA.MTA_EVENT", "MTA.MTA_SOW_EVENT", "MTA.MTA_SOW_WORK_TYPE_XREF", "MTA.MTA_WORK_TYPE_CODE", "MTA.MTA_WORK_TYPE_ITEM_CODE"]

fieldList = [["MTA_SPATIAL.MTA_ACQUIRED_TENURE_SVW.TENURE_NUMBER_ID", 'Tenure_Number'],
             ["MTA.MTA_EVENT.EVENT_NUMBER_ID", 'Event_Number'],
             ["MTA_SPATIAL.MTA_ACQUIRED_TENURE_SVW.TENURE_TYPE_DESCRIPTION", 'Tenure_Type'],
             ["MTA_SPATIAL.MTA_ACQUIRED_TENURE_SVW.TENURE_SUB_TYPE_DESCRIPTION",'Tenure_Sub_Type'],
             ["MTA_SPATIAL.MTA_ACQUIRED_TENURE_SVW.TITLE_TYPE_DESCRIPTION", 'Title_Type'],
             ["MTA_SPATIAL.MTA_ACQUIRED_TENURE_SVW.ISSUE_DATE", 'Issue_Date'],
             ["MTA_SPATIAL.MTA_ACQUIRED_TENURE_SVW.GOOD_TO_DATE", 'Good_to_Date'],
             ["MTA_SPATIAL.MTA_ACQUIRED_TENURE_SVW.OWNER_NAME", 'Owner_Name'],
             ["LISTAGG(MTA.MTA_WORK_TYPE_ITEM_CODE.DESCRIPTION, '; ')WITHIN GROUP (ORDER BY MTA.MTA_WORK_TYPE_ITEM_CODE.DESCRIPTION)", 'Work_Type_Items'],
             ["MTA.MTA_WORK_TYPE_ITEM_CODE.DESCRIPTION", 'Work_Type_Items'],
             ["MTA.MTA_EVENT.DATA_ENTRY_DATE", 'Data_Entry_Date'],
             ["MTA.MTA_SOW_EVENT.AMOUNT", 'Amount']]

whereClause = """MTA_SPATIAL.MTA_ACQUIRED_TENURE_SVW.TENURE_NUMBER_ID = MTA.MTA_TENURE_EVENT_XREF.TENURE_NUMBER_ID and
             MTA.MTA_TENURE_EVENT_XREF.EVENT_NUMBER_ID = MTA.MTA_EVENT.EVENT_NUMBER_ID and
             MTA.MTA_EVENT.EVENT_NUMBER_ID = MTA.MTA_SOW_EVENT.EVENT_NUMBER_ID and
             MTA.MTA_SOW_EVENT.EVENT_NUMBER_ID = MTA.MTA_SOW_WORK_TYPE_XREF.EVENT_NUMBER_ID and
             MTA.MTA_SOW_EVENT.MTA_WORK_TYPE_CODE = MTA.MTA_WORK_TYPE_CODE.MTA_WORK_TYPE_CODE and
             MTA.MTA_SOW_WORK_TYPE_XREF.MTA_WORK_TYPE_ITEM_CODE = MTA.MTA_WORK_TYPE_ITEM_CODE.MTA_WORK_TYPE_ITEM_CODE and
             MTA.MTA_EVENT.MTA_EVENT_TYPE_CODE = 'SOW' and
             MTA.MTA_SOW_EVENT.mta_work_type_code = 'P' and
             MTA.MTA_EVENT.DATA_ENTRY_DATE between (sysdate-365) and (sysdate) and MTA.MTA_EVENT.COMMITTED_IND = 'Y' and
             MTA.MTA_TENURE_EVENT_XREF.TENURE_NUMBER_ID = 230428
             group by
             MTA_SPATIAL.MTA_ACQUIRED_TENURE_SVW.TENURE_NUMBER_ID,
             MTA.MTA_EVENT.EVENT_NUMBER_ID,
             MTA_SPATIAL.MTA_ACQUIRED_TENURE_SVW.OWNER_NAME,
             MTA.MTA_WORK_TYPE_CODE.DESCRIPTION,
             MTA.MTA_SOW_EVENT.AMOUNT,
             MTA_SPATIAL.MTA_ACQUIRED_TENURE_SVW.TENURE_TYPE_DESCRIPTION,                 MTA_SPATIAL.MTA_ACQUIRED_TENURE_SVW.TENURE_SUB_TYPE_DESCRIPTION,
             MTA_SPATIAL.MTA_ACQUIRED_TENURE_SVW.TITLE_TYPE_DESCRIPTION,
             MTA_SPATIAL.MTA_ACQUIRED_TENURE_SVW.ISSUE_DATE,
             MTA.MTA_EVENT.DATA_ENTRY_DATE,
             MTA.MTA_EVENT.GOOD_TO_DATE"""

keyField = "MTA_SPATIAL.MTA_ACQUIRED_TENURE_SVW.TENURE_NUMBER_ID; MTA.MTA_EVENT.EVENT_NUMBER_ID"

lyrName = "Test_Table2"
# Make Query Table...
arcpy.MakeQueryTable_management(tableList, lyrName,"USE_KEY_FIELDS", keyField, fieldList, whereClause)

0 个答案:

没有答案