外部连接运算符错误



早些时候,我只在一个条件下过滤我的查询。 即project_id 但是现在我又添加了两个过滤条件。他们是

  1. 日期在

  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>

相关内容

最新更新