环境:oracle11g,PLSQL9.0
1.不加条件查询结果
2.添加MOTYPE = '16'的条件查询结果
3.添加MOTYPE = '11'的查询结果
说明:从1中我们可以看出,有两条符合MOTYPE = '16'的数据,但是我们添加条件查询不到数据,有两条符合MOTYPE = '11',添加查询条件后可以查到,所以,遇到的问题是为什么MOTYPE = '16'查不到数据?
分析:其中符合MOTYPE = '16'的两条数据的特点是TBLNaturalOrderQty有,但是TBLWHMOCOEFFICIENT没有,这两张表用 full join进行连接。
求大牛帮我分析一下原因是为什么,非常感谢。
-- Create table create table TBLNATURALORDERQTY ( yearmonth VARCHAR2(40) not null, motype VARCHAR2(40) not null, orgid VARCHAR2(40), naturalorderqty NUMBER(22,2) ) tablespace FHDEMO pctfree 10 initrans 1 maxtrans 255 storage ( initial 64 next 8 minextents 1 maxextents unlimited ); -- Add comments to the columns comment on column TBLNATURALORDERQTY.yearmonth is '年月'; comment on column TBLNATURALORDERQTY.motype is '工单类型'; comment on column TBLNATURALORDERQTY.orgid is '组织代码'; comment on column TBLNATURALORDERQTY.naturalorderqty is '自然订单量'; -- Create table create table TBLWHMOCOEFFICIENT ( motype VARCHAR2(40) not null, coefficient NUMBER(22,10) not null, muser VARCHAR2(40) not null, mdate NUMBER(8) not null, mtime NUMBER(6) not null ) tablespace FHDEMO pctfree 10 initrans 1 maxtrans 255 storage ( initial 64 next 1 minextents 1 maxextents unlimited ); -- Create/Recreate primary, unique and foreign key constraints alter table TBLWHMOCOEFFICIENT add constraint TBLWHMOCOEFFICIENT_PK primary key (MOTYPE) using index tablespace FHDEMO pctfree 10 initrans 2 maxtrans 255 storage ( initial 64K next 1M minextents 1 maxextents unlimited );
insert into TBLWHMOCOEFFICIENT (MOTYPE, COEFFICIENT, MUSER, MDATE, MTIME) values ('12', 1.0000000000, '0211001888', 20151210, 145319); insert into TBLWHMOCOEFFICIENT (MOTYPE, COEFFICIENT, MUSER, MDATE, MTIME) values ('77', 3.0200000000, 'ADMIN', 20151203, 113907); insert into TBLWHMOCOEFFICIENT (MOTYPE, COEFFICIENT, MUSER, MDATE, MTIME) values ('78', 3.3300000000, 'ADMIN', 20151203, 114033); insert into TBLWHMOCOEFFICIENT (MOTYPE, COEFFICIENT, MUSER, MDATE, MTIME) values ('99', 1.2500000000, 'ADMIN', 20151207, 134046); insert into TBLWHMOCOEFFICIENT (MOTYPE, COEFFICIENT, MUSER, MDATE, MTIME) values ('50', 2.0900000000, 'ADMIN', 20151105, 120000); insert into TBLWHMOCOEFFICIENT (MOTYPE, COEFFICIENT, MUSER, MDATE, MTIME) values ('11', 0.1500000000, 'ADMIN', 20151105, 120000); insert into TBLWHMOCOEFFICIENT (MOTYPE, COEFFICIENT, MUSER, MDATE, MTIME) values ('14', 0.9600000000, 'ADMIN', 20151105, 120000); insert into TBLWHMOCOEFFICIENT (MOTYPE, COEFFICIENT, MUSER, MDATE, MTIME) values ('15', 0.6400000000, 'ADMIN', 20151105, 120000); insert into TBLWHMOCOEFFICIENT (MOTYPE, COEFFICIENT, MUSER, MDATE, MTIME) values ('18', 0.1000000000, 'ADMIN', 20151105, 120000); insert into TBLWHMOCOEFFICIENT (MOTYPE, COEFFICIENT, MUSER, MDATE, MTIME) values ('19', 0.2400000000, 'ADMIN', 20151105, 120000); insert into TBLWHMOCOEFFICIENT (MOTYPE, COEFFICIENT, MUSER, MDATE, MTIME) values ('20', 0.4100000000, 'ADMIN', 20151105, 120000); insert into TBLWHMOCOEFFICIENT (MOTYPE, COEFFICIENT, MUSER, MDATE, MTIME) values ('51', 2.0900000000, 'ADMIN', 20151105, 120000); insert into TBLWHMOCOEFFICIENT (MOTYPE, COEFFICIENT, MUSER, MDATE, MTIME) values ('52', 0.7600000000, 'ADMIN', 20151105, 120000); insert into TBLWHMOCOEFFICIENT (MOTYPE, COEFFICIENT, MUSER, MDATE, MTIME) values ('53', 0.2000000000, 'ADMIN', 20151105, 120000); insert into TBLWHMOCOEFFICIENT (MOTYPE, COEFFICIENT, MUSER, MDATE, MTIME) values ('56', 4.9900000000, 'ADMIN', 20151105, 120000); insert into TBLWHMOCOEFFICIENT (MOTYPE, COEFFICIENT, MUSER, MDATE, MTIME) values ('70', 4.0400000000, 'ADMIN', 20151206, 231146); insert into TBLWHMOCOEFFICIENT (MOTYPE, COEFFICIENT, MUSER, MDATE, MTIME) values ('79', 3.3230000000, 'ADMIN', 20151203, 114434);
insert into TBLNaturalOrderQty (YEARMONTH, MOTYPE, ORGID, NATURALORDERQTY) values ('201511', '11', '100', 300.00); insert into TBLNaturalOrderQty (YEARMONTH, MOTYPE, ORGID, NATURALORDERQTY) values ('201511', '12', '100', 350.00); insert into TBLNaturalOrderQty (YEARMONTH, MOTYPE, ORGID, NATURALORDERQTY) values ('201511', '15', '100', 200.00); insert into TBLNaturalOrderQty (YEARMONTH, MOTYPE, ORGID, NATURALORDERQTY) values ('201511', '16', '100', 250.00); insert into TBLNaturalOrderQty (YEARMONTH, MOTYPE, ORGID, NATURALORDERQTY) values ('201511', '50', '100', 100.00); insert into TBLNaturalOrderQty (YEARMONTH, MOTYPE, ORGID, NATURALORDERQTY) values ('201510', '11', '100', 2000.00); insert into TBLNaturalOrderQty (YEARMONTH, MOTYPE, ORGID, NATURALORDERQTY) values ('201510', '12', '100', 2500.00); insert into TBLNaturalOrderQty (YEARMONTH, MOTYPE, ORGID, NATURALORDERQTY) values ('201510', '15', '100', 3000.00); insert into TBLNaturalOrderQty (YEARMONTH, MOTYPE, ORGID, NATURALORDERQTY) values ('201510', '16', '100', 3500.00);
可能16后面带了个空格
没有带空格,你可以自己试试看。
@盛强: 麻烦再把查询语句贴出来一下