2015-04-27 70 views
-1

我創建了一個臨時表和一個存儲函數來讀取它。當我打電話給下面的消息出現:Oracle存儲函數與臨時表

RA-22905: Zugriff auf Zeilen eines Objekts, das keine Nested Table ist, nicht möglich 
22905. 00000 - "cannot access rows from a non-nested table item" 
*Cause: attempt to access rows of an item whose type is not known at 
      parse time or that is not of a nested table type 
*Action: use CAST to cast the item to a nested table type 
Fehler in Zeile: 3 Spalte: 15 

那麼,我該怎麼做CAST的事呢?

我心愛的功能:

create or replace PACKAGE BODY testlho2 IS 
    FUNCTION getBasicDate (app_in IN varchar2, termc_in IN varchar2) 
    return sys_refcursor is 
    l_rc SYS_REFCURSOR; 
    BEGIN 
    -- Populate temporary table 
    INSERT INTO temp_tab_test_lho2 (app, sla, tsl) 
     SELECT app, sla, tslstat 
     FROM pmon_orig_file 
     WHERE app = app_in and termcause = termc_in; 
    -- Open REF CURSOR for Output 
    open l_rc for 
     select app, sla, tsl 
     from temp_tab_test_lho2; 
    return l_rc; 
    END; 
END testlho2 ; 
+0

[ORA-22905 - quering SELECT語句的表類型時]的可能重複(http://stackoverflow.com/questions/19208264/ ora-22905-when-quering-a-table-type-with-a-select-statement) –

+0

對不起,我的晶球失靈了。如果你發佈你的功能,也許有人會說如何修復它。 –

+0

創建或替換PACKAGE BODY testlho2 IS FUNCTION getBasicDate(app_in IN varchar2,termc_in IN varchar2)return sys_refcursor is l_rc SYS_REFCURSOR; BEGIN ( - 填充臨時表) INSERT INTO temp_tab_test_lho2 (應用程序,SLA,TSL) SELECT應用,SLA,tslstat FROM pmon_orig_file WHERE應用程式= app_in \t和termcause = termc_in; ( - 打開REF CURSOR輸出) 打開l_rc 選擇應用程序,sla,tsl from temp_tab_test_lho2; return l_rc; END; END testlho2; – user

回答

0

臨時表:

create global temporary table tbl(name_ varchar2(50)) 
/

功能:

create or replace function foo(app_in IN varchar2) 
return sys_refcursor is 
l_rc SYS_REFCURSOR; 
begin 
    insert into tbl select app_in from dual; 
    open l_rc for select name_ from tbl; 
    return l_rc; 
end; 
/

從功能選擇數據:

select * from table(foo('hiiii')); 

錯誤:

ORA-22905: cannot access rows from a non-nested table item 
22905. 00000 - "cannot access rows from a non-nested table item" 

如果一個人想使用的功能上面它必須返回一個type。 看到以下問題:

Function return sys_refcursor call from sql with specific columns

如果你在一個匿名塊使用函數,那麼它會工作:

declare 
l_rc SYS_REFCURSOR; 
begin 
l_rc := foo('hiii'); 
end; 
/

anonymous block completed 

即使你type解決的返回類型的問題,如果你使用在select聲明中的功能,那麼它會錯誤地說:

ORA-14551: cannot perform a DML operation inside a query 
14551. 00000 - "cannot perform a DML operation inside a query " 

這說如何能夠解決上述問題

Solution to "cannot perform a DML operation inside a query"?