oracle 不使用ANSL删除旧样式外部联接或添加左联接

nhhxz33t  于 2023-03-22  发布在  Oracle
关注(0)|答案(1)|浏览(286)

添加字段Assignment_type,在表PER_ALL_ASSIGNMENTS_F中找到。当前状态sql在where节中使用(+)outter joins。当添加ansl左腰时,我得到错误'ORA-25156:旧样式的外部联接(+)不能与ANSI联接一起使用
我尝试删除连接并使用ansl格式添加,但我得到了不同的结果。

SELECT
'XX' KEY,
EE.RECEIPT_MISSING_FLAG,
EE.RECEIPT_REQUIRED_FLAG,
EE.RECEIPT_TIME,
EET.NAME EXPENSE_TYPE,
EE.EXPENSE_TYPE_CATEGORY_CODE,
PREP.PERSON_NUMBER PREPARER_PERSON_NBR,
EER.EXPENSE_REPORT_TOTAL,
EE.REIMBURSABLE_AMOUNT,
EE.RECEIPT_AMOUNT,
EE.EXPENSE_ID,
EE.EMP_DEFAULT_COST_CENTER,
EE.NUMBER_OF_ATTENDEES,
replace(replace(replace(replace(replace(replace(replace(EE.DESCRIPTION,chr(9),''),chr(10),''),chr(11),''),chr(12),''),chr(13),''),chr(124),''),chr(34),'') EXPENSE_DESCR,
replace(replace(replace(replace(replace(replace(replace(EER.PURPOSE,chr(9),''),chr(10),''),chr(11),''),chr(12),''),chr(13),''),chr(124),''),chr(34),'') EXP_PURPOSE,
EER.EXPENSE_REPORT_NUM EXPENSE_REPORT_NUM,
PER.PERSON_NUMBER PERSON_NBR,
to_char(EER.EXPENSE_REPORT_DATE,'YYYY-MM-DD') EXP_REPORT_DATE,
CAPPR.PERSON_NUMBER CURRENT_APPR_PERSON_NBR,
to_char(EER.FINAL_APPROVAL_DATE,'YYYY-MM-DD') EXP_APPROVAL_DATE,
HOUFL.NAME BUSINESS_UNIT,
EER.AUDIT_CODE,
LADTBY.PERSON_NUMBER LAST_AUDIT_PERSON_NBR,
EER.AUDIT_RETURN_REASON_CODE,
EER.AUDIT_PRIOR_MGR_STATUS_CODE,
replace(replace(replace(replace(replace(replace(replace(EE.JUSTIFICATION,chr(9),''),chr(10),''),chr(11),''),chr(12),''),chr(13),''),chr(124),''),chr(34),'') EXP_JUSTIFICATION,
to_char(EE.START_DATE,'YYYY-MM-DD') EXP_START_DATE,
EE.TIP_AMOUNT,
EE.EXPENSE_SOURCE,
EE.MERCHANT_NAME,
EE.VEHICLE_CATEGORY_CODE,
EE.VEHICLE_TYPE,
EE.DAILY_DISTANCE,
EE.DISTANCE_UNIT_CODE,
EE.TRIP_DISTANCE,
EE.TICKET_CLASS_CODE,
EE.TICKET_NUMBER,
EE.FLIGHT_NUMBER,
EE.RANGE_LOW,
EE.RANGE_HIGH,
EE.LOCATION,
EER.EXPENSE_STATUS_CODE,

(CASE
              WHEN ASSIGNMENT_TYPE = 'E' THEN 'Employee'
              WHEN ASSIGNMENT_TYPE = 'C' THEN 'Contractor'
              WHEN ASSIGNMENT_TYPE = 'N' THEN 'Nonworker'
              WHEN ASSIGNMENT_TYPE = 'P' THEN 'Pending'
              WHEN ASSIGNMENT_TYPE = 'O' THEN 'Offered'
              ELSE TO_CHAR (ASSIGNMENT_TYPE)
END) ASSIGNMENT_TYPE,
EE.DESTINATION_FROM DESTINATION_FROM, 
EE.DESTINATION_TO DESTINATION_TO,
to_char(EE.START_DATE,'YYYY-MM-DD') TRANSACTION_DATE
FROM EXM_EXPENSES EE,
EXM_EXPENSE_REPORTS EER,
PER_ALL_PEOPLE_F PER,
HR_ORGANIZATION_UNITS_F_TL HOUFL,
PER_ALL_PEOPLE_F PREP,
EXM_EXPENSE_TYPES EET,
PER_ALL_PEOPLE_F CAPPR,
PER_ALL_PEOPLE_F LADTBY
Left Join PER_ALL_ASSIGNMENTS_F ASS
On LADTY.person_ID = ASS.Person_ID

WHERE EE.EXPENSE_REPORT_ID = EER.EXPENSE_REPORT_ID
AND EER.EXPENSE_REPORT_DATE BETWEEN NVL(:START_DATE,trunc(Last_Day(ADD_MONTHS(SYSDATE,-2))+1)) AND NVL(:END_DATE,Last_Day(ADD_MONTHS(sysdate,-1)))
AND EER.PERSON_ID = PER.PERSON_ID(+)
AND TRUNC(SYSDATE) BETWEEN TRUNC(PER.EFFECTIVE_START_DATE(+))   AND TRUNC(PER.EFFECTIVE_END_DATE(+))
AND EER.ORG_ID = HOUFL.ORGANIZATION_ID(+)
AND HOUFL.LANGUAGE(+)          = 'US'
AND TRUNC(SYSDATE) BETWEEN TRUNC(HOUFL.EFFECTIVE_START_DATE(+)) AND TRUNC(HOUFL.EFFECTIVE_END_DATE(+))
AND EE.PREPARER_ID = PREP.PERSON_ID(+)
AND TRUNC(SYSDATE) BETWEEN TRUNC(PREP.EFFECTIVE_START_DATE(+))   AND TRUNC(PREP.EFFECTIVE_END_DATE(+))
AND EE.EXPENSE_TYPE_ID = EET.EXPENSE_TYPE_ID
AND EER.CURRENT_APPROVER_ID = CAPPR.PERSON_ID(+)
AND TRUNC(SYSDATE) BETWEEN TRUNC(CAPPR.EFFECTIVE_START_DATE(+))   AND TRUNC(CAPPR.EFFECTIVE_END_DATE(+))
AND EER.LAST_AUDIT_BY = LADTBY.PERSON_ID(+)
AND TRUNC(SYSDATE) BETWEEN TRUNC(LADTBY.EFFECTIVE_START_DATE(+))   AND TRUNC(LADTBY.EFFECTIVE_END_DATE(+))
and Primary_flag = 'Y'
And Ass.Person_ID = PER.Person_ID
And ASS.Effective_End_date > Sysdate
And ASSIGNMENT_STATUS_TYPE = 'ACTIVE'
AND ASSIGNMENT_TYPE IN ('E', 'C', 'N', 'P', 'O' )
ORDER BY EER.EXPENSE_REPORT_NUM
svgewumm

svgewumm1#

最简单、最安全的做法是使用Oracle原生语法添加新的连接,就像所有其他连接一样:

SELECT
  'XX' KEY,
  EE.RECEIPT_MISSING_FLAG,
  EE.RECEIPT_REQUIRED_FLAG,
  EE.RECEIPT_TIME,
  EET.NAME EXPENSE_TYPE,
  EE.EXPENSE_TYPE_CATEGORY_CODE,
  PREP.PERSON_NUMBER PREPARER_PERSON_NBR,
  EER.EXPENSE_REPORT_TOTAL,
  EE.REIMBURSABLE_AMOUNT,
  EE.RECEIPT_AMOUNT,
  EE.EXPENSE_ID,
  EE.EMP_DEFAULT_COST_CENTER,
  EE.NUMBER_OF_ATTENDEES,
  replace(replace(replace(replace(replace(replace(replace(EE.DESCRIPTION,chr(9),''),chr(10),''),chr(11),''),chr(12),''),chr(13),''),chr(124),''),chr(34),'') EXPENSE_DESCR,
  replace(replace(replace(replace(replace(replace(replace(EER.PURPOSE,chr(9),''),chr(10),''),chr(11),''),chr(12),''),chr(13),''),chr(124),''),chr(34),'') EXP_PURPOSE,
  EER.EXPENSE_REPORT_NUM EXPENSE_REPORT_NUM,
  PER.PERSON_NUMBER PERSON_NBR,
  to_char(EER.EXPENSE_REPORT_DATE,'YYYY-MM-DD') EXP_REPORT_DATE,
  CAPPR.PERSON_NUMBER CURRENT_APPR_PERSON_NBR,
  to_char(EER.FINAL_APPROVAL_DATE,'YYYY-MM-DD') EXP_APPROVAL_DATE,
  HOUFL.NAME BUSINESS_UNIT,
  EER.AUDIT_CODE,
  LADTBY.PERSON_NUMBER LAST_AUDIT_PERSON_NBR,
  EER.AUDIT_RETURN_REASON_CODE,
  EER.AUDIT_PRIOR_MGR_STATUS_CODE,
  replace(replace(replace(replace(replace(replace(replace(EE.JUSTIFICATION,chr(9),''),chr(10),''),chr(11),''),chr(12),''),chr(13),''),chr(124),''),chr(34),'') EXP_JUSTIFICATION,
  to_char(EE.START_DATE,'YYYY-MM-DD') EXP_START_DATE,
  EE.TIP_AMOUNT,
  EE.EXPENSE_SOURCE,
  EE.MERCHANT_NAME,
  EE.VEHICLE_CATEGORY_CODE,
  EE.VEHICLE_TYPE,
  EE.DAILY_DISTANCE,
  EE.DISTANCE_UNIT_CODE,
  EE.TRIP_DISTANCE,
  EE.TICKET_CLASS_CODE,
  EE.TICKET_NUMBER,
  EE.FLIGHT_NUMBER,
  EE.RANGE_LOW,
  EE.RANGE_HIGH,
  EE.LOCATION,
  EER.EXPENSE_STATUS_CODE,

  (CASE
                WHEN ASSIGNMENT_TYPE = 'E' THEN 'Employee'
                WHEN ASSIGNMENT_TYPE = 'C' THEN 'Contractor'
                WHEN ASSIGNMENT_TYPE = 'N' THEN 'Nonworker'
                WHEN ASSIGNMENT_TYPE = 'P' THEN 'Pending'
                WHEN ASSIGNMENT_TYPE = 'O' THEN 'Offered'
                ELSE TO_CHAR (ASSIGNMENT_TYPE)
  END) ASSIGNMENT_TYPE,
  EE.DESTINATION_FROM DESTINATION_FROM, 
  EE.DESTINATION_TO DESTINATION_TO,
  to_char(EE.START_DATE,'YYYY-MM-DD') TRANSACTION_DATE
  FROM EXM_EXPENSES EE,
  EXM_EXPENSE_REPORTS EER,
  PER_ALL_PEOPLE_F PER,
  HR_ORGANIZATION_UNITS_F_TL HOUFL,
  PER_ALL_PEOPLE_F PREP,
  EXM_EXPENSE_TYPES EET,
  PER_ALL_PEOPLE_F CAPPR,
  PER_ALL_PEOPLE_F LADTBY,
  PER_ALL_ASSIGNMENTS_F ASS
  WHERE EE.EXPENSE_REPORT_ID = EER.EXPENSE_REPORT_ID
  AND EER.EXPENSE_REPORT_DATE BETWEEN NVL(:START_DATE,trunc(Last_Day(ADD_MONTHS(SYSDATE,-2))+1)) AND NVL(:END_DATE,Last_Day(ADD_MONTHS(sysdate,-1)))
  AND EER.PERSON_ID = PER.PERSON_ID(+)
  AND TRUNC(SYSDATE) BETWEEN TRUNC(PER.EFFECTIVE_START_DATE(+))   AND TRUNC(PER.EFFECTIVE_END_DATE(+))
  AND EER.ORG_ID = HOUFL.ORGANIZATION_ID(+)
  AND HOUFL.LANGUAGE(+)          = 'US'
  AND TRUNC(SYSDATE) BETWEEN TRUNC(HOUFL.EFFECTIVE_START_DATE(+)) AND TRUNC(HOUFL.EFFECTIVE_END_DATE(+))
  AND EE.PREPARER_ID = PREP.PERSON_ID(+)
  AND TRUNC(SYSDATE) BETWEEN TRUNC(PREP.EFFECTIVE_START_DATE(+))   AND TRUNC(PREP.EFFECTIVE_END_DATE(+))
  AND EE.EXPENSE_TYPE_ID = EET.EXPENSE_TYPE_ID
  AND EER.CURRENT_APPROVER_ID = CAPPR.PERSON_ID(+)
  AND TRUNC(SYSDATE) BETWEEN TRUNC(CAPPR.EFFECTIVE_START_DATE(+))   AND TRUNC(CAPPR.EFFECTIVE_END_DATE(+))
  AND EER.LAST_AUDIT_BY = LADTBY.PERSON_ID(+)
  AND TRUNC(SYSDATE) BETWEEN TRUNC(LADTBY.EFFECTIVE_START_DATE(+))   AND TRUNC(LADTBY.EFFECTIVE_END_DATE(+))

  AND LADTBY.PERSON_ID = ASS.PERSON_ID(+)
  AND TRUNC(SYSDATE) BETWEEN TRUNC(ASS.EFFECTIVE_START_DATE(+))   AND TRUNC(ASS.EFFECTIVE_END_DATE(+))

  and Primary_flag = 'Y'
  And Ass.Person_ID = PER.Person_ID
  And ASS.Effective_End_date > Sysdate
  And ASSIGNMENT_STATUS_TYPE = 'ACTIVE'
  AND ASSIGNMENT_TYPE IN ('E', 'C', 'N', 'P', 'O' )
  ORDER BY EER.EXPENSE_REPORT_NUM

假设这个ASS和你在这里的其他表有相同的类型2日期安排,我包括了日期过滤器。如果它不是类型2,你当然会删除它。

相关问题