Sql 使用ROWNUM筛选器的默认列上的空值
我对Oracle数据库11.2.0.1.0有这种奇怪的行为 使用此表:Sql 使用ROWNUM筛选器的默认列上的空值,sql,database,oracle,hibernate,oracle11gr2,Sql,Database,Oracle,Hibernate,Oracle11gr2,我对Oracle数据库11.2.0.1.0有这种奇怪的行为 使用此表: CREATE TABLE "COMPANIES" ( "ID" NUMBER(19,0) NOT NULL ENABLE, "COMMENTS" VARCHAR2(3999 CHAR), "NAME" VARCHAR2(126 CHAR) NOT NULL ENABLE, "IDENTIFICATIONCODE" VARCHAR2(126 CHAR), "REMOVALDATE" TIMESTAMP
CREATE TABLE "COMPANIES"
( "ID" NUMBER(19,0) NOT NULL ENABLE,
"COMMENTS" VARCHAR2(3999 CHAR),
"NAME" VARCHAR2(126 CHAR) NOT NULL ENABLE,
"IDENTIFICATIONCODE" VARCHAR2(126 CHAR),
"REMOVALDATE" TIMESTAMP (6),
"BLACKLIST" NUMBER(1,0) DEFAULT 0 NOT NULL ENABLE,
"BLACKLISTREASON_ID" NUMBER(19,0),
"BLACKLISTCOMMENTS" VARCHAR2(3999 CHAR),
CONSTRAINT "COMPANIES_PK" PRIMARY KEY ("ID")
此查询返回此结果集:
SELECT id643_1_, blacklist643_1_ FROM (
select this_.id AS id643_1_,this_.blacklist AS blacklist643_1_
from companies this_
where this_.id IN (
SELECT DISTINCT this2_.id AS y0_
FROM companies this2_
WHERE ( this2_.removaldate IS NULL OR this2_.removaldate >= to_timestamp('03/06/2019 00:00:00.000','mm/dd/yyyy hh24:mi:ss.ff3')))
ORDER BY this_.name ASC
) WHERE ROWNUM <= 2147483647;
id643_1_ blacklist643_1_
3869594 [NULL]
3869596 [NULL]
3869597 [NULL]
3869592 [NULL]
3869598 [NULL]
3869599 [NULL]
但要删除ROWNUM筛选器,请执行以下操作之一:
SELECT id643_1_, blacklist643_1_ FROM (
select this_.id AS id643_1_,this_.blacklist AS blacklist643_1_
from companies this_
where this_.id IN (
SELECT DISTINCT this2_.id AS y0_
FROM companies this2_
WHERE ( this2_.removaldate IS NULL OR this2_.removaldate >= to_timestamp('03/06/2019 00:00:00.000','mm/dd/yyyy hh24:mi:ss.ff3')))
ORDER BY this_.name ASC
)
--WHERE ROWNUM <= 2147483647;
id643_1_ blacklist643_1_
3869594 0
3869596 0
3869597 0
3869592 0
3869598 0
3869599 0
或内置过滤器:
SELECT id643_1_, blacklist643_1_ FROM (
select this_.id AS id643_1_,this_.blacklist AS blacklist643_1_
from companies this_
--where this_.id IN (
--SELECT DISTINCT this2_.id AS y0_
--FROM companies this2_
--WHERE ( this2_.removaldate IS NULL OR this2_.removaldate >= to_timestamp('03/06/2019 00:00:00.000','mm/dd/yyyy hh24:mi:ss.ff3')))
--ORDER BY this_.name ASC
)
WHERE ROWNUM <= 2147483647;
id643_1_ blacklist643_1_
3869594 0
3869596 0
3869597 0
3869592 0
3869598 0
3869599 0
它返回正确的默认值
查询别名是由hibernate生成的,不过它已经在jvm外部进行了测试,所以我认为这不是hibernate或jpa相关的问题
我不知道为什么会这样
更新1:
相似表,相似查询:
select * from (
select *
from incidents this_
where this_.id in (select tab2.id from incidents tab2)
order by this_.id
) where rownum <= 1000;
id BLACKLIST FAILED FAILEDDATE
1100071 0 0 [NULL]
1100112 0 1 2013-01-28 00:00:00
1100155 0 0 [NULL]
1100203 0 0 [NULL]
1100241 0 0 [NULL]
1100301 0 0 [NULL]
而且ROWNUM更大:
select * from (
select *
from incidents this_
where this_.id in (select tab2.id from incidents tab2)
order by this_.id
) where rownum <= 1000000;
id BLACKLIST FAILED FAILEDDATE
1100071 [NULL] [NULL] [NULL]
1100112 [NULL] [NULL] [NULL]
1100155 [NULL] [NULL] [NULL]
1100203 [NULL] [NULL] [NULL]
1100241 [NULL] [NULL] [NULL]
1100301 [NULL] [NULL] [NULL]
更新2:
它不会发生在11.2.0.3.0上,所以我猜这是一个bug。如果有人遇到这个问题,我会把问题留着