SELECT *
FROM (SELECT *
FROM (SELECT O.ID,
O.SPEC_ID,
O.ORDER_SPEC_ID,
O.ORDER_TYPE_ID,
O.ORDER_CODE,
O.ORDER_NAME,
O.ORDER_STATE_ID,
to_char(O.REQ_COMP_TIME, 'YYYY-MM-DD HH24:MI:SS') REQ_COMP_TIME,
O.IS_OVERHAUL_ID,
TO_CHAR(O.CREATE_START_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_START_TIME,
TO_CHAR(O.CREATE_END_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_END_TIME,
TO_CHAR(O.DEAL_TIME, 'YYYY-MM-DD HH24:MI:SS') DEAL_TIME,
TO_CHAR(O.COMPLETED_TIME, 'YYYY-MM-DD HH24:MI:SS') COMPLETED_TIME,
O.MOVEMENT_TYPE,
O.LEND_MARK,
O.CREATOR_ID,
O.MODIFIER_ID,
O.DELETER_ID,
TO_CHAR(O.CREATE_DATE, 'YYYY-MM-DD HH24:MI:SS') CREATE_DATE,
TO_CHAR(O.MODIFY_DATE, 'YYYY-MM-DD HH24:MI:SS') MODIFY_DATE,
TO_CHAR(O.DELETE_DATE, 'YYYY-MM-DD HH24:MI:SS') DELETE_DATE,
O.CREATOR,
O.MODIFIER,
O.DELETER,
O.ORG_CODE,
O.ORG_NAME,
O.TACH_CODE,
O.PROCESS_CODE,
O.VERSION,
O.MSS_ORDER_CODE,
O.ENGINEER_MANAGER,
O.SHARDING_ID,
O.IS_CREATEPROJECT_ID,
O.IS_ZGZC_ID,
O.AREA_CODE,
O.TACHID,
O.CREATOR_NAME,
O.MOVE_IN,
O.MOVE_OUT,
O.SAPCOMPANYNAME,
O.REASON,
O.NOTES,
O.ORG_SYSTEM_CODE,
O.IS_MODIFY_ID,
TO_CHAR(O.AUDIT_TIME_MSS, 'YYYY-MM-DD HH24:MI:SS') AUDIT_TIME_MSS,
O.AUDITTER_MSS,
O.MSG_MSS
FROM PM_ASSET_ORDER O
WHERE 1 = 1
AND O.ENGINEER_MANAGER = '33019619@ZJ'
union all
select *
from PM_ASSET_ORDER O
where exists
(select 1
from X_ASSET_INFO t1
where t1.ASSETKEEPER = '33019619@ZJ'
and t1.PROJECT_ASSET_CONFIR_MORDER_ID = O.ID
UNION ALL
SELECT 1
FROM PM_ASSET_ORDER PA
WHERE PA.CREATOR_ID = '331110000000000000297893'
AND PA.ORDER_STATE_ID = 0
AND PA.ID = O.ID)) M
WHERE 1 = 1
AND M.ORDER_STATE_ID = '0'
AND M.ORDER_STATE_ID IN (0, 1, 2, 3))
WHERE ROWNUM < 101
错误原因:
union 和union 的字段的排序需要和后面的排序一致
UNION 使用必须保证表连接时数据类型是一致的。检查一个类型,你可以少连接几个字段,逐项排查加减字段进行调试
解决:
SELECT *
FROM (SELECT *
FROM (SELECT O.ID,
O.SPEC_ID,
O.ORDER_SPEC_ID,
O.ORDER_TYPE_ID,
O.ORDER_CODE,
O.ORDER_NAME,
O.ORDER_STATE_ID,
TO_CHAR(O.REQ_COMP_TIME, 'YYYY-MM-DD HH24:MI:SS') REQ_COMP_TIME,
O.IS_OVERHAUL_ID,
TO_CHAR(O.CREATE_START_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_START_TIME,
TO_CHAR(O.CREATE_END_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_END_TIME,
TO_CHAR(O.DEAL_TIME, 'YYYY-MM-DD HH24:MI:SS') DEAL_TIME,
TO_CHAR(O.COMPLETED_TIME, 'YYYY-MM-DD HH24:MI:SS') COMPLETED_TIME,
O.MOVEMENT_TYPE,
O.LEND_MARK,
O.CREATOR_ID,
O.MODIFIER_ID,
O.DELETER_ID,
TO_CHAR(O.CREATE_DATE, 'YYYY-MM-DD HH24:MI:SS') CREATE_DATE,
TO_CHAR(O.MODIFY_DATE, 'YYYY-MM-DD HH24:MI:SS') MODIFY_DATE,
TO_CHAR(O.DELETE_DATE, 'YYYY-MM-DD HH24:MI:SS') DELETE_DATE,
O.CREATOR,
O.MODIFIER,
O.DELETER,
O.ORG_CODE,
O.ORG_NAME,
O.TACH_CODE,
O.PROCESS_CODE,
O.VERSION,
O.MSS_ORDER_CODE,
O.ENGINEER_MANAGER,
O.SHARDING_ID,
O.IS_CREATEPROJECT_ID,
O.IS_ZGZC_ID,
O.AREA_CODE,
O.TACHID,
O.CREATOR_NAME,
O.MOVE_IN,
O.MOVE_OUT,
O.SAPCOMPANYNAME,
O.REASON,
O.NOTES,
O.ORG_SYSTEM_CODE,
O.IS_MODIFY_ID,
TO_CHAR(O.AUDIT_TIME_MSS, 'YYYY-MM-DD HH24:MI:SS') AUDIT_TIME_MSS,
O.AUDITTER_MSS,
O.MSG_MSS
FROM PM_ASSET_ORDER O
WHERE 1 = 1
AND O.ENGINEER_MANAGER = '33019619@ZJ'
union all
select O.ID,
O.SPEC_ID,
O.ORDER_SPEC_ID,
O.ORDER_TYPE_ID,
O.ORDER_CODE,
O.ORDER_NAME,
O.ORDER_STATE_ID,
TO_CHAR(O.REQ_COMP_TIME, 'YYYY-MM-DD HH24:MI:SS') REQ_COMP_TIME,
O.IS_OVERHAUL_ID,
TO_CHAR(O.CREATE_START_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_START_TIME,
TO_CHAR(O.CREATE_END_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_END_TIME,
TO_CHAR(O.DEAL_TIME, 'YYYY-MM-DD HH24:MI:SS') DEAL_TIME,
TO_CHAR(O.COMPLETED_TIME, 'YYYY-MM-DD HH24:MI:SS') COMPLETED_TIME,
O.MOVEMENT_TYPE,
O.LEND_MARK,
O.CREATOR_ID,
O.MODIFIER_ID,
O.DELETER_ID,
TO_CHAR(O.CREATE_DATE, 'YYYY-MM-DD HH24:MI:SS') CREATE_DATE,
TO_CHAR(O.MODIFY_DATE, 'YYYY-MM-DD HH24:MI:SS') MODIFY_DATE,
TO_CHAR(O.DELETE_DATE, 'YYYY-MM-DD HH24:MI:SS') DELETE_DATE,
O.CREATOR,
O.MODIFIER,
O.DELETER,
O.ORG_CODE,
O.ORG_NAME,
O.TACH_CODE,
O.PROCESS_CODE,
O.VERSION,
O.MSS_ORDER_CODE,
O.ENGINEER_MANAGER,
O.SHARDING_ID,
O.IS_CREATEPROJECT_ID,
O.IS_ZGZC_ID,
O.AREA_CODE,
O.TACHID,
O.CREATOR_NAME,
O.MOVE_IN,
O.MOVE_OUT,
O.SAPCOMPANYNAME,
O.REASON,
O.NOTES,
O.ORG_SYSTEM_CODE,
O.IS_MODIFY_ID,
TO_CHAR(O.AUDIT_TIME_MSS, 'YYYY-MM-DD HH24:MI:SS') AUDIT_TIME_MSS,
O.AUDITTER_MSS,
O.MSG_MSS
from PM_ASSET_ORDER O
where exists
(select 1
from X_ASSET_INFO t1
where t1.ASSETKEEPER = '33019619@ZJ'
and t1.PROJECT_ASSET_CONFIR_MORDER_ID = O.ID
UNION ALL
SELECT 1
FROM PM_ASSET_ORDER PA
WHERE PA.CREATOR_ID = '331110000000000000297893'
AND PA.ORDER_STATE_ID = 0
AND PA.ID = O.ID)) M
WHERE 1 = 1
AND M.ORDER_STATE_ID = '0'
AND M.ORDER_STATE_ID IN (0, 1, 2, 3))
WHERE ROWNUM < 101