HI Team这是我用旧语法
的exisitng oracle查询select * from
USER us,
USER_EXTGBL ue,
STTMS_BRANCH_EXTGBL be,
ROLE_MASTER rm,
USER_ROLE ur
where us.user_id = ue.USER_ID
and us.USER_ID = ur.user_id(+)
and ur.ROLE_ID = rm.ROLE_ID
and us.HOME_BRANCH = be.BRANCH_CODE
and us.AUTH_STAT='A' and us.RECORD_STAT='O'
and rm.AUTH_STAT='A' and rm.RECORD_STAT='O'
and us.HOME_LEGAL_VEHICLE = ur.LEGAL_VEHICLE_CODE(+)
and us.HOME_BRANCH = ur.branch_code(+)
and us.home_branch in (select branch_code from sttms_branch where country_code= $Country_Code)
我正面临着重写新oracle语法的挑战,因为当我在地方使用左/右连接时我无法使用where条件。有人帮我改写查询
答案 0 :(得分:2)
USER_ROLE
似乎只是外部联合。实际上ur.ROLE_ID = rm.ROLE_ID
确保所有外连接记录都被解除,并且连接最终是内连接。所以这都是内在联盟:
select *
from user us
join user_extgbl ue on us.user_id = ue.user_id
join sttms_branch_extgbl be on us.home_branch = be.branch_code
join user_role ur on us.user_id = ur.user_id
and us.home_legal_vehicle = ur.legal_vehicle_code
and us.home_branch = ur.branch_code
join role_master rm on ur.role_id = rm.role_id
and us.auth_stat = rm.auth_stat
and us.record_stat = rm.record_stat
where us.auth_stat = 'A'
and us.record_stat = 'O'
and us.home_branch in
(select branch_code from sttms_branch where country_code= $country_code);
如果您想加入外部加入USER_ROLE
,则还必须加入外部加入ROLE_MASTER
。
答案 1 :(得分:0)
select *
from USER us
INNER JOIN USER_EXTGBL ue
ON ( us.user_id = ue.USER_ID )
LEFT OUTER JOIN USER_ROLE ur
ON ( us.USER_ID = ur.user_id
AND us.HOME_LEGAL_VEHICLE = ur.LEGAL_VEHICLE_CODE
AND us.HOME_BRANCH = ur.branch_code )
INNER JOIN ROLE_MASTER rm
ON ( ur.ROLE_ID = rm.ROLE_ID )
INNER JOIN STTMS_BRANCH_EXTGBL be
ON ( us.HOME_BRANCH = be.BRANCH_CODE )
where us.AUTH_STAT='A' and us.RECORD_STAT='O'
and rm.AUTH_STAT='A' and rm.RECORD_STAT='O'
and us.home_branch in ( select branch_code
from sttms_branch
where country_code = $Country_Code )
答案 2 :(得分:0)
SELECT *
FROM USER us
INNER JOIN user_extgbl ue ON us.user_id = ue.user_id
INNER JOIN user_role ur
ON us.user_id = ur.user_id
AND us.home_legal_vehicle = ur.legal_vehicle_code
AND us.home_branch = ur.branch_code
INNER JOIN sttms_branch_extgbl be ON us.home_branch = be.branch_code
INNER JOIN role_master rm ON ur.role_id = rm.role_id
WHERE us.auth_stat = 'A'
AND us.record_stat = 'O'
AND rm.auth_stat = 'A'
AND rm.record_stat = 'O'
AND us.home_branch IN (SELECT branch_code
FROM sttms_branch
WHERE country_code = country_code)