繁体   English   中英

外部联接运算符错误

[英]Outer join operator error

之前,我仅在一种情况下过滤查询。 project_id但现在我又添加了两个过滤条件。 他们是

  1. 日期IN

  2. 车辆编号

我尝试了以下查询

SELECT DISTINCT sv.mkey, vehicle_no,
               TO_CHAR (date_in, 'dd/MM/yyyy')
            || ' & '
            || time_in vehicleindate_time,
               TO_CHAR (date_out, 'dd/MM/yyyy')
            || ' & '
            || time_out vehicleoutdate_time,
            gate_no_in || ' & ' || gate_no_out ingate_outgateno,
            gd.good_type goods_type, net_weight netweight,
               TO_CHAR (challan_date, 'dd/MM/yyyy')
            || ' & '
            || challan_no challandate_no,
            remark_in remarkin, NULL receipt_no, date_in
       FROM xxcus.xxgid_supinv sv,
            xxcus.xx_supinv_goodtype gd,
            xxcus.xxacl_xxgid_user_mst ms
      WHERE gd.good_type_code(+) = sv.good_type AND sv.project_id = 1469
         OR TO_CHAR (date_in, 'dd/MM/yyyy') = '09/01/2015'
         OR vehicle_no = '79'
   ORDER BY date_in DESC, vehicle_no

但是有错误

ORA-01719:OR或IN的操作数中不允许使用外部联接运算符(+)

我不知道这里出了什么问题。 友善建议

您需要使用显式的JOIN ,还需要定义将xxcus.xxacl_xxgid_user_mst ms连接到查询的其余部分的方式。

SELECT DISTINCT sv.mkey, vehicle_no,
                TO_CHAR (date_in, 'dd/MM/yyyy') || ' & ' || time_in vehicleindate_time,
                TO_CHAR (date_out, 'dd/MM/yyyy') || ' & ' || time_out vehicleoutdate_time,
                gate_no_in || ' & ' || gate_no_out ingate_outgateno,
                gd.good_type goods_type, net_weight netweight,
                TO_CHAR (challan_date, 'dd/MM/yyyy') || ' & ' || challan_no challandate_no,
                remark_in remarkin, NULL receipt_no, date_in
FROM xxcus.xxgid_supinv sv
RIGHT OUTER JOIN xxcus.xx_supinv_goodtype gd ON sv.good_type = gd.good_type_code
XXXX JOIN xxcus.xxacl_xxgid_user_mst ms ON XX.XXXXX ON ms.XXXXX
WHERE sv.project_id = 1469
OR TO_CHAR (date_in, 'dd/MM/yyyy') = '09/01/2015'
OR vehicle_no = '79'
ORDER BY date_in DESC, vehicle_no

您正在使用(+)语法,该语法不允许使用OR条件; 您可以使用显式的OUTER JOIN重新编写查询; 例如:

SQL> create table table_id ( id number);

Table created.

SQL> create table table_desc ( id number, description varchar2(255));

Table created.

SQL> begin
  2  insert into table_id values (1);
  3  insert into table_id values (2);
  4  insert into table_id values (3);
  5  insert into table_desc values (1, 'ONE');
  6  insert into table_desc values (3, 'THREE');
  7  insert into table_desc values (3, 'Three');
  8  end;
  9  /

PL/SQL procedure successfully completed.

错误的方法:

SQL> select *
  2  from table_id id, table_desc des
  3  where id.id = des.id(+)
  4    and des.description = 'Three' OR des.description = 'THREE';
where id.id = des.id(+)
            *
ERROR at line 3:
ORA-01719: outer join operator (+) not allowed in operand of OR or IN

正确的路:

SQL> select id.id, des.description
  2  from table_id id
  3       LEFT OUTER JOIN table_desc des
  4        ON id.id = des.id
  5  where des.description = 'Three' OR des.description = 'THREE';

        ID DESCRIPTION
---------- -------------------
         3 Three
         3 THREE

SQL>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM