小编典典

Oracle查询给出错误

sql

我在蟾蜍中的查询下面运行以测试结果,但由于出现错误

ORA-00933:SQL命令未正确结束

这是我的查询

SELECT DISTINCT sv.mkey, vehicle_no, 'ABC' isnullcheck,
               TO_CHAR (date_in, 'dd-MM-yyyy')
            || ' & '
            || time_in vehicleindate_time,
               TO_CHAR (date_out, 'dd-MM-yyyy')
            || ' & '
            || time_out vehicleoutdate_time,
            gate_no_in || ' & ' || gate_no_out ingate_outgateno,
            gd.good_type goods_type, net_weight netweight,
               TO_CHAR (challan_date, 'dd-MM-yyyy')
            || ' & '
            || challan_no challandate_no,
            remark_in remarkin, NULL receipt_no, date_in
       FROM xxcus.xxgid_supinv sv,
            xxcus.xx_supinv_goodtype gd,
            xxcus.xxacl_xxgid_user_mst ms
      WHERE gd.good_type_code(+) = sv.good_type
        AND sv.project_id = 1368
        AND (sv.audit_flag IS NULL OR sv.audit_flag = 'N') UNION SELECT DISTINCT sv.mkey, vehicle_no, 'XYZ' portfolio,
               TO_CHAR (date_in, 'dd-MM-yyyy')
            || ' & '
            || time_in vehicleindate_time,
               TO_CHAR (date_out, 'dd-MM-yyyy')
            || ' & '
            || time_out vehicleoutdate_time,
            gate_no_in || ' & ' || gate_no_out ingate_outgateno,
            gd.good_type goods_type, net_weight netweight,
               TO_CHAR (challan_date, 'dd-MM-yyyy')
            || ' & '
            || challan_no challandate_no,
            remark_in remarkin, NULL receipt_no, date_in
       FROM xxcus.xxgid_supinv sv,
            xxcus.xx_supinv_goodtype gd,
            xxcus.xxacl_xxgid_user_mst ms
      WHERE gd.good_type_code(+) = sv.good_type
        AND sv.project_id = 1368
        AND sv.audit_flag IS NULL
   ORDER BY isnullcheck, date_in DESC, vehicle_no UNION
              SELECT NULL, 0, 'ABC', NULL, NULL, NULL,
                     'ABC', NULL, NULL, NULL, NULL, NULL, NULL
                FROM DUAL
              UNION
              SELECT NULL, 0, 'XYZ', NULL, NULL, NULL,
                     'XYZ', NULL, NULL, NULL, NULL, NULL, NULL
                FROM DUAL

请暗示这里有什么问题


阅读 140

收藏
2021-04-15

共1个答案

小编典典

您的两个较大的SELECTS(前两个)将返回12个项目。最后两个SELECTS(较小的SELECTS)返回13个项目。UNION必须具有匹配的列。

例如,声明应结束…

SELECT NULL, 0, 'ABC', NULL, NULL, NULL,
'ABC', NULL, NULL, NULL, NULL, NULL
FROM DUAL

UNION

SELECT NULL, 0, 'XYZ', NULL, NULL, NULL,
'XYZ', NULL, NULL, NULL, NULL, NULL
FROM DUAL
2021-04-15