我有大量的Oracle查询,但我希望在下面的代码行中有RIGHT JOIN
,我尝试使用(+)但不起作用:
AND SUBSTR(IBT_LINE.USER_1, 0, INSTR(IBT_LINE.USER_1, '-', +1, 3)-1) =
SUBSTR(WORK_ORDER.USER_1, 0, INSTR(WORK_ORDER.USER_1, '-', +1, 3)-1)
总查询:
FROM
CUSTOMER_ORDER, IBT, IBT_LINE,PART, WORK_ORDER
WHERE
CUSTOMER_ORDER.ID = REPLACE(IBT.ID,'X','C')
AND IBT.ID = IBT_LINE.IBT_ID
AND IBT_LINE.PART_ID=PART.ID
AND SUBSTR(IBT_LINE.USER_1, 0, INSTR(IBT_LINE.USER_1, '-', +1, 3)-1) = SUBSTR(WORK_ORDER.USER_1, 0, INSTR(WORK_ORDER.USER_1, '-', +1, 3)-1)
AND WORK_ORDER.WAREHOUSE_ID ='MEX-04' AND WORK_ORDER.STATUS ='R'
答案 0 :(得分:1)
使用两个表进行右/左连接是不可能的,并且在同一个select中该表的字段上具有强制值。 你的问题不在于sintax(+或JOIN),你的选择就是问题。
您正在尝试在WORK_ORDER和IBT_LINE中获得外部联接,但是您告诉oracle使用此句子进行完全联接:
.... AND WORK_ORDER.WAREHOUSE_ID ='MEX-04'和WORK_ORDER.STATUS ='R'
您可以在FROM中尝试子选择,
....
FROM
CUSTOMER_ORDER, IBT, IBT_LINE,PART,
(SELECT SUBSTR(WORK_ORDER.USER_1, 0, INSTR(WORK_ORDER.USER_1, '-', +1, 3)-1) user_1_formatted
from WORK_ORDER
where WORK_ORDER.WAREHOUSE_ID ='MEX-04'
AND WORK_ORDER.STATUS ='R') sub_work_order
WHERE
CUSTOMER_ORDER.ID = REPLACE(IBT.ID,'X','C')
AND IBT.ID = IBT_LINE.IBT_ID
AND IBT_LINE.PART_ID=PART.ID
AND SUBSTR(IBT_LINE.USER_1, 0, INSTR(IBT_LINE.USER_1, '-', +1, 3)-1) = sub_work_order.user_1_formatted(+)
或子选择,然后根据需要过滤结果。
select *
from (select ... from
CUSTOMER_ORDER, IBT, IBT_LINE,PART, WORK_ORDER
WHERE
CUSTOMER_ORDER.ID = REPLACE(IBT.ID,'X','C')
AND IBT.ID = IBT_LINE.IBT_ID
AND IBT_LINE.PART_ID=PART.ID
AND SUBSTR(IBT_LINE.USER_1, 0, INSTR(IBT_LINE.USER_1, '-', +1, 3)-1) = SUBSTR(WORK_ORDER.USER_1, 0, INSTR(WORK_ORDER.USER_1, '-', +1, 3)-1) (+))
where (work_order is null or (WORK_ORDER.WAREHOUSE_ID ='MEX-04' AND WORK_ORDER.STATUS ='R'))