Условие OR
, упомянутое в сообщении об ошибке внешнего соединения, находится в разделе фильтра '&psRate_type'
, который, я не думаю, вы намеревались стать частью объединения. Если вы заключите в скобки все эти условия внутри предиката AND
, ошибка исчезнет:
select distinct
rp.rp_record_id
, rp.rate_profile_name
, rph.rate_type
, rph.charge_code
, rph.transport_mode
, rph.place_of_receipt_code
, rph.origin_type
, rph.destination_type
from rate_profile rp
, rate_profile_header rph
, partner_charge_profile pcp
, partner
, commodity_codes com
, offices
, partner_relationships pr
, company_partners cp
, employee e
where rp.rp_record_id = rph.rp_record_id
and pcp.partner_id = partner.partner_id
and com.cc_record_id (+) = rph.commcode_record_id
and pcp.company_id = offices.company_id
and offices.office_type = 'T'
and pr.partner_id (+) = partner.partner_id
and pr.employee_no = e.employee_no
and partner.partner_id = cp.partner_id
and cp.company_id = '&CompanyID'
and cp.company_id = pcp.company_id
and cp.company_id (+) = pr.company_id
and pcp.charge_code = rph.charge_code
and pcp.charge_calculation_method = 'R'
and rph.rp_record_id = pcp.charge_rateprof_record_id
-- Added brackets below:
and ( ('&psRate_type' = 'SEL' and rph.rate_type = 'SEL' and pcp.charge_calculation_method = 'R' and rph.rp_record_id = pcp.charge_rateprof_record_id)
or ('&psRate_type' = 'BUY' and rph.rate_type = 'BUY' and pcp.cost_calculation_method = 'R' and rph.rp_record_id = pcp.cost_rateprof_record_id)
or ('&psRate_type' = 'All'
and ( (rph.rate_type = 'SEL' and pcp.charge_calculation_method = 'R' and rph.rp_record_id = pcp.cost_rateprof_record_id)
or (rph.rate_type = 'BUY' and pcp.cost_calculation_method = 'R' and rph.rp_record_id = pcp.cost_rateprof_record_id))
)
);
Однако company_partners
не может быть внешним соединением, потому что cp.company_id = '&CompanyID'
. То же самое относится и к partner_relationships
, потому что pr.employee_no = e.employee_no
. Единственное реальное внешнее соединение - это commodity_codes
, который в любом случае не используется в запросе и может быть удален без влияния на результат.
Учитывая это, я получаю в качестве версии ANSI следующее:
select distinct
rp.rp_record_id
, rp.rate_profile_name
, rph.rate_type
, rph.charge_code
, rph.transport_mode
, rph.place_of_receipt_code
, rph.origin_type
, rph.destination_type
from company_partners cp
join partner_relationships pr
on pr.company_id = cp.company_id
and pr.partner_id = cp.partner_id
/*join partner -- not needed if pr.partner_id is a FK to partner
on partner.partner_id = pr.partner_id*/
join partner_charge_profile pcp
on pcp.company_id = cp.company_id
and pcp.partner_id = cp.partner_id
join rate_profile_header rph
on rph.charge_code = pcp.charge_code
and rph.rp_record_id = pcp.charge_rateprof_record_id
join rate_profile rp
on rp.rp_record_id = rph.rp_record_id
join employee e
on e.employee_no = pr.employee_no
join offices
on offices.company_id = pcp.company_id
/*left join commodity_codes com -- not used
on com.cc_record_id = rph.commcode_record_id*/
where cp.company_id = '&CompanyID'
and pcp.charge_calculation_method = 'R'
and offices.office_type = 'T'
and ( ('&psRate_type' = 'SEL' and rph.rate_type = 'SEL' and pcp.charge_calculation_method = 'R')
or ('&psRate_type' = 'BUY' and rph.rate_type = 'BUY' and pcp.cost_calculation_method = 'R' and rph.rp_record_id = pcp.cost_rateprof_record_id)
or ('&psRate_type' = 'All'
and ( (rph.rate_type = 'SEL' and pcp.charge_calculation_method = 'R' and rph.rp_record_id = pcp.cost_rateprof_record_id)
or (rph.rate_type = 'BUY' and pcp.cost_calculation_method = 'R' and rph.rp_record_id = pcp.cost_rateprof_record_id)))
);