2015-12-15 40 views
0
CREATE OR REPLACE TYPE record_AB AS OBJECT 
    (
     AA VARCHAR2 (32767 BYTE), 
     BB VARCHAR2 (32767 BYTE) 
    ); 
    /

CREATE OR REPLACE TYPE type_tab_AB IS TABLE OF record_AB; 
    /


SQL> VARIABLE curs1 REFCURSOR; 
SQL> 
SQL> DECLARE 
    2 tab_AB type_tab_AB; 
    3 begin 
    4 select system.record_AB(t.owner,t.table_name) bulk collect into tab_AB from dba_tables t where compression='ENABLED' and compress_for='OLTP'; 
    5 open :curs1 for select * from table(tab_AB) ; 
    6 end; 
    7/

PL/SQL procedure successfully completed. 

SQL> select * from dba_segments where (owner,segment_name) in (select :curs1 from dual); 
select * from dba_segments where (owner,segment_name) in (select :curs1 from dual) 

ERROR at line 1: 
ORA-00947: not enough values 

我需要爲業主和SEGMENT_NAME提供AA的值,光標光標1的BB列作爲輸入,可有人請告訴我們如何實現這一目標?無法從遊標變量傳遞列的值來選擇查詢

回答

0

您不能選擇遊標變量,只能打開,取出並關閉它。你想達到什麼目的?沒有必要在所有在這裏使用一個REF CURSOR:

select * from dba_segments 
where (owner,segment_name) in 
(select t.owner,t.table_name 
    from dba_tables t 
    where compression='ENABLED' 
    and compress_for='OLTP'); 

但是,如果你的代碼的目的是與裁判光標玩,而不是圖段數據,那麼這個答案可能不是你想要的。

使用表:

create table enabled_oltp_tables as 
select t.owner,t.table_name 
from dba_tables t 
where compression='ENABLED' 
and compress_for='OLTP'; 

select * from dba_segments 
where (owner,segment_name) in 
(select t.owner,t.table_name 
    from enabled_oltp_tables t 
); 
+0

我requriment是之前和之後解壓縮到段的大小比較。所以我試圖將壓縮段(所有者和段名稱)的列表存儲在遊標變量中。解壓縮後,我需要獲取這些段的大小。我們不能在解壓縮後使用您的代碼bcos「select d。t.table,t.table_name from dba_tables t where compression ='ENABLED' and compress_for ='OLTP'」這不會導致任何行 – newbee

+0

爲什麼不保存它們一張桌子? –

+0

謝謝Tony。這是一次性任務,所以我們試圖不使用表格。有沒有其他方法? – newbee

0

嗨。剛剛經歷了這個問題。以爲你可以嘗試像這樣的 。讓我知道,如果這有助於

--Create object type 
CREATE OR REPLACE TYPE record_AB 
AS 
    OBJECT 
    (
    AA VARCHAR2 (32767 BYTE), 
    BB VARCHAR2 (32767 BYTE)); 

--Create table type 
CREATE OR REPLACE TYPE type_tab_AB 
IS 
    TABLE OF record_AB; 

--Plsql block to perform action 
    var ref_c refcursor; 
    DECLARE 
    tab_AB type_tab_AB; 
    BEGIN 
    SELECT record_AB(t.owner,t.table_name) bulk collect 
    INTO tab_AB 
    FROM all_tables t 
    WHERE compression='ENABLED'; 
    OPEN :ref_c FOR SELECT * FROM dba_segments WHERE (owner,segment_name) IN 
    (SELECT t.aa,t.bb FROM TABLE(tab_AB) t 
    ); 
    END; 

    Print ref_c;