使用Oracle 10g的分页加入查询时出错

时间:2017-10-17 16:51:02

标签: sql oracle pagination oracle10g

我在SqlDeveloper中执行此查询,目标是Oracle 10g中的数据库:

select P1.FIELD1, P1.COD from 
(select P1.FIELD1, P1.COD, row_number() 
over (order by P1.FIELD1) r from 
SCHEMA1.P2 
INNER JOIN SCHEMA1.P1 on SCHEMA1.P1.COD=P2.FIELD2) 
where P1.FIELD_11 = 'VALUE1' and r between 6 and 10;

Oracle回归:

Error SQL: ORA-00904: "P1"."FIELD_11": invalid identifier

我试过了:

select SCHEMA1.P1.FIELD1, SCHEMA1.P1.COD from 
(select SCHEMA1.P1.FIELD1, SCHEMA1.P1.COD, row_number() 
over (order by SCHEMA1.P1.FIELD1) r from 
SCHEMA1.P2 
INNER JOIN SCHEMA1.P1 on SCHEMA1.P1.COD=SCHEMA1.P2.FIELD2) 
where SCHEMA1.P1.FIELD_11 = 'VALUE1' and r between 6 and 10;

我得到了同样的错误:

ORA-00904: "SCHEMA1"."P1"."FIELD_11": invalid identifier

我找不到带有内部联接和分页的select子句的例子,因为我不知道我做错了什么。

1 个答案:

答案 0 :(得分:2)

您已将查询与别名混淆,这会让人感到困惑。使用较短的别名而不是整个schema.table.column

SELECT p.field1,
       p.cod
FROM   (SELECT p1.field1,
               p1.cod,
           p1.field_11,
               row_number()
                 over (
                   ORDER BY p1.field1) r
        FROM   schema1.p2 p2
               inner join schema1.p1 p1
                       ON p1.cod = p2.field2) p
WHERE  p.field_11 = 'VALUE1'
       AND r BETWEEN 6 AND 10;