此查询
select id from TABLE where id=1234 or id like '234%'
按预期返回11行。但是当我尝试这个
select rownum as rnum, id from TABLE where id=1234 or id like '234%'
甚至是这个
select * from (
select id from TABLE where id=1234 or id like '234%'
) where rownum < 22
我只有10行(输出记录集中缺少id = 1234
)。为什么会这样?
表TABLE的DDL
CREATE TABLE "TABLE"
( "ID" NUMBER(28,0),
"SPOT_LCK" NUMBER(28,0),
"STATUS" NUMBER(*,0),
"CARRIER_YN" CHAR(1 BYTE),
...
"DRIVER" NUMBER(38,0) DEFAULT 0
);
表TABLE的约束
ALTER TABLE "SCHEMA"."TABLE" ADD CONSTRAINT "PK_TBL" PRIMARY KEY ("ID")
Oracle 12c版本12.1.0.2.0-64位
答案 0 :(得分:1)
仔细检查您的结果,您肯定犯了一个错误。最小示例:
create table testrn ( id number primary key, c1 number );
insert into testrn values (1234, 1);
insert into testrn values (2341, 2);
insert into testrn values (2342, 3);
insert into testrn values (2343, 4);
insert into testrn values (2344, 5);
insert into testrn values (2345, 6);
insert into testrn values (2346, 7);
insert into testrn values (2347, 8);
insert into testrn values (2348, 9);
insert into testrn values (2349, 10);
insert into testrn values (23410, 11);
commit;
select id, rownum from testrn where id=1234 or id like '234%';
这将按预期返回11行。我假设您的意思是缺少1234,因为在SQL中未使用123?
答案 1 :(得分:0)
目前尚未找到解决方案:oracle表示需要最新补丁,应用程序供应商表示不支持该补丁。所以我们照原样离开。