Oracle SQL偏移行号

时间:2012-12-14 05:25:28

标签: java sql oracle offset

我正在尝试创建一个可以帮助我找到检查点行的变量,然后查询该检查点之后的行。

首先,我考虑使用ROWID,但ROWID的形式是非Integer。这似乎有点不合适。

无论如何,一个必需的过程是创建一个Rows偏移量,这在Oracle中不方便支持:

我一直在

  

ORA-00904:“ITEM”。“ID”:标识符无效

该变量是Item_ID,它是表ITEM的ID列。

select ITEM.ID,ITEM.CREATEDDATE,ITEM.TYPEID,
        CAT_DIC_AUTHOR.DISPLAYENTRY,
        CAT_DIC_PUBLISHER.DISPLAYENTRY,
        CAT_DIC_KEYWORD.ACCESSENTRY,CAT_DIC_KEYWORD.DISPLAYENTRY,
        CAT_DIC_LANGUAGE.DISPLAYENTRY,CAT_DIC_LANGUAGE.NAMEVIET,
        CAT_DIC_SH.DISPLAYENTRY,
        CAT_DIC_ITEM_TYPE.ACCESSENTRY,CAT_DIC_ITEM_TYPE.TYPENAME 
from ( select rownum r,ITEM.ID from ITEM) 

LEFT JOIN ITEM_AUTHOR 
    ON ITEM.ID=ITEM_AUTHOR.ITEMID 
LEFT JOIN CAT_DIC_AUTHOR 
    ON ITEM_AUTHOR.AUTHORID=CAT_DIC_AUTHOR.ID 
LEFT JOIN ITEM_PUBLISHER 
    ON ITEM.ID=ITEM_PUBLISHER.ITEMID 
LEFT JOIN CAT_DIC_PUBLISHER 
    ON ITEM_PUBLISHER.PUBLISHERID=CAT_DIC_PUBLISHER.ID 
LEFT JOIN ITEM_KEYWORD 
    ON ITEM.ID=ITEM_KEYWORD.ITEMID 
LEFT JOIN CAT_DIC_KEYWORD 
    ON ITEM_KEYWORD.KEYWORDID=CAT_DIC_KEYWORD.ID 
LEFT JOIN ITEM_LANGUAGE 
    ON ITEM.ID=ITEM_LANGUAGE.ITEMID 
LEFT JOIN CAT_DIC_LANGUAGE 
    ON ITEM_LANGUAGE.LANGUAGEID=CAT_DIC_LANGUAGE.ID 
LEFT JOIN ITEM_SH 
    ON ITEM.ID=ITEM_SH.ITEMID 
LEFT JOIN CAT_DIC_SH 
    ON ITEM_SH.SHID=CAT_DIC_SH.ID 
LEFT JOIN CAT_DIC_ITEM_TYPE 
    ON ITEM.TYPEID=CAT_DIC_ITEM_TYPE.ID 

where r>100 and r<=200

1 个答案:

答案 0 :(得分:2)

尝试在子查询后添加ITEM字,如下所示:

select ITEM.ID,ITEM.CREATEDDATE,ITEM.TYPEID,
        CAT_DIC_AUTHOR.DISPLAYENTRY,
        CAT_DIC_PUBLISHER.DISPLAYENTRY,
        CAT_DIC_KEYWORD.ACCESSENTRY,CAT_DIC_KEYWORD.DISPLAYENTRY,
        CAT_DIC_LANGUAGE.DISPLAYENTRY,CAT_DIC_LANGUAGE.NAMEVIET,
        CAT_DIC_SH.DISPLAYENTRY,
        CAT_DIC_ITEM_TYPE.ACCESSENTRY,CAT_DIC_ITEM_TYPE.TYPENAME 
from ( select rownum r,ITEM.ID,ITEM.TYPEID, ITEM.CREATEDDATE from ITEM)  ITEM

LEFT JOIN ITEM_AUTHOR 
    ON ITEM.ID=ITEM_AUTHOR.ITEMID 
LEFT JOIN CAT_DIC_AUTHOR 
    ON ITEM_AUTHOR.AUTHORID=CAT_DIC_AUTHOR.ID 
LEFT JOIN ITEM_PUBLISHER 
    ON ITEM.ID=ITEM_PUBLISHER.ITEMID 
LEFT JOIN CAT_DIC_PUBLISHER 
    ON ITEM_PUBLISHER.PUBLISHERID=CAT_DIC_PUBLISHER.ID 
LEFT JOIN ITEM_KEYWORD 
    ON ITEM.ID=ITEM_KEYWORD.ITEMID 
LEFT JOIN CAT_DIC_KEYWORD 
    ON ITEM_KEYWORD.KEYWORDID=CAT_DIC_KEYWORD.ID 
LEFT JOIN ITEM_LANGUAGE 
    ON ITEM.ID=ITEM_LANGUAGE.ITEMID 
LEFT JOIN CAT_DIC_LANGUAGE 
    ON ITEM_LANGUAGE.LANGUAGEID=CAT_DIC_LANGUAGE.ID 
LEFT JOIN ITEM_SH 
    ON ITEM.ID=ITEM_SH.ITEMID 
LEFT JOIN CAT_DIC_SH 
    ON ITEM_SH.SHID=CAT_DIC_SH.ID 
LEFT JOIN CAT_DIC_ITEM_TYPE 
    ON ITEM.TYPEID=CAT_DIC_ITEM_TYPE.ID 
where r>100 and r<=200