2017-10-17 86 views
0

我執行這個查詢中的SQLDeveloper針對Oracle 10g中一個數據庫:錯誤加入與分頁查詢適用於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 

我找不到Oracle內部連接和分頁的select子句的例子,所以我不知道我在做什麼錯誤。

回答

2

你搞亂查詢與它confusing.use這使得短的別名來代替別名全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;