2014-11-03 101 views
1

我嘗試以下操作:商店ROWID在Oracle對象類型

CREATE TYPE T_TEST AS OBJECT (
    TEST_ROWID    ROWID, 
    TEST_DATA     NUMBER(12) 
); 
/

但我得到一個錯誤:

ORA-24344: success with compilation error 
PLS-00530: Illegal type used for object type attribute: 'ROWID'. 

我想存儲的rowid的,因爲它們比索引查找速度更快。

實現上述目標的好方法是什麼?從VARCHAR2投射和從VARCHAR2可能會引入儘可能多的開銷與使用索引?

回答

1

您的類型定義中至少有兩個錯誤。

Nonquoted identifiers cannot be Oracle SQL reserved words. Quoted identifiers can be reserved words, although this is not recommended.

Note: The reserved word ROWID is an exception to this rule. You cannot use the uppercase word ROWID, either quoted or nonquoted, as a column name. However, you can use the uppercase word as a quoted identifier that is not a column name, and you can use the word with one or more lowercase letters (for example, "Rowid" or "rowid") as any quoted identifier, including a column name.

所以你不能使用ROWID作爲變量名。

第二個是你不能使用ROWID類型。如果你嘗試,你會得到PLS-00530

據我所知有CHARTOROWID/ROWIDTOCHAR功能可能有所幫助。

+0

對不起,第一個錯誤是一個錯字。它被稱爲'TEST_ROWID'和'TEST_DATA',然後我刪除了TEST後綴以「改善閱讀」......將調整。 – 2014-11-03 14:29:29

+0

@davor好的,你打算使用哪個索引?只是不要將函數應用於索引列 – Multisync 2014-11-03 14:31:36

+0

而不是'ROWID'我可以使用表的主鍵('NUMBER(20)')。 – 2014-11-03 14:34:53