2017-01-30 61 views
0

我正在嘗試通過過程獲取V $ RESOURCE_LIMIT結果的Oracle DBMS_OUTPUT。

但是,我收到有關c1不完整或格式錯誤的錯誤。

到目前爲止,我有以下代碼:

CREATE OR REPLACE PROCEDURE resource_output AS 

CURSOR c1 IS SELECT resource_name , current_utilization , max_utilization , initial_allocation , limit_value FROM v$resource_limit; 
TYPE rl_typ IS TABLE OF c1%ROWTYPE; 
rl rl_typ; 

BEGIN 
dbms_output.enable(100000); 

    FOR rl IN (
    select * BULK COLLECT INTO rl from v$resource_limit 
) 
    LOOP 
    DBMS_OUTPUT.PUT_LINE('Resource Name = ' || rl.resource_name || 
         ', Current Utilization = ' || rl.current_utilization || 
         ', Max Utilization = ' || rl.max_utilization || 
         ', Initial Allocation = ' || rl.initial_allocation || 
         ', Limit Value = ' || rl.limit_value); 
    END LOOP; 

END resource_output; 
+1

爲什麼要在PL/SQL代碼中執行此操作? – mathguy

回答

0
CREATE OR REPLACE PROCEDURE resource_output AS 


BEGIN 
dbms_output.enable(100000); 

    FOR rl IN (
    select * from v$resource_limit 
) 
    LOOP 
    DBMS_OUTPUT.PUT_LINE('Resource Name = ' || rl.resource_name || 
         ', Current Utilization = ' || rl.current_utilization || 
         ', Max Utilization = ' || rl.max_utilization || 
         ', Initial Allocation = ' || rl.initial_allocation || 
         ', Limit Value = ' || rl.limit_value); 
    END LOOP; 

END resource_output; 

exec resource_output; 

輸出:

Resource Name = processes, Current Utilization = 103, Max Utilization = 179, Initial Allocation =  900, Limit Value =  900 
Resource Name = sessions, Current Utilization = 117, Max Utilization = 212, Initial Allocation =  1372, Limit Value =  1372 
Resource Name = enqueue_locks, Current Utilization = 105, Max Utilization = 223, Initial Allocation =  15820, Limit Value =  15820 
Resource Name = enqueue_resources, Current Utilization = 35, Max Utilization = 94, Initial Allocation =  6256, Limit Value = UNLIMITED 
Resource Name = ges_procs, Current Utilization = 0, Max Utilization = 0, Initial Allocation =   0, Limit Value =   0 
Resource Name = ges_ress, Current Utilization = 0, Max Utilization = 0, Initial Allocation =   0, Limit Value = UNLIMITED 
Resource Name = ges_locks, Current Utilization = 0, Max Utilization = 0, Initial Allocation =   0, Limit Value = UNLIMITED 
Resource Name = ges_cache_ress, Current Utilization = 0, Max Utilization = 0, Initial Allocation =   0, Limit Value = UNLIMITED 
Resource Name = ges_reg_msgs, Current Utilization = 0, Max Utilization = 0, Initial Allocation =   0, Limit Value = UNLIMITED 
Resource Name = ges_big_msgs, Current Utilization = 0, Max Utilization = 0, Initial Allocation =   0, Limit Value = UNLIMITED 
Resource Name = ges_rsv_msgs, Current Utilization = 0, Max Utilization = 0, Initial Allocation =   0, Limit Value =   0 
Resource Name = gcs_resources, Current Utilization = 0, Max Utilization = 0, Initial Allocation = UNLIMITED, Limit Value = UNLIMITED 
Resource Name = gcs_shadows, Current Utilization = 0, Max Utilization = 0, Initial Allocation = UNLIMITED, Limit Value = UNLIMITED 
Resource Name = smartio_overhead_memory, Current Utilization = 0, Max Utilization = 68632, Initial Allocation =   0, Limit Value = UNLIMITED 
Resource Name = smartio_buffer_memory, Current Utilization = 0, Max Utilization = 0, Initial Allocation =   0, Limit Value = UNLIMITED 
Resource Name = smartio_metadata_memory, Current Utilization = 0, Max Utilization = 0, Initial Allocation =   0, Limit Value = UNLIMITED 
Resource Name = smartio_sessions, Current Utilization = 0, Max Utilization = 1, Initial Allocation =   0, Limit Value = UNLIMITED 
Resource Name = dml_locks, Current Utilization = 0, Max Utilization = 0, Initial Allocation =  6036, Limit Value = UNLIMITED 
Resource Name = temporary_table_locks, Current Utilization = 0, Max Utilization = 65, Initial Allocation = UNLIMITED, Limit Value = UNLIMITED 
Resource Name = transactions, Current Utilization = 5, Max Utilization = 5, Initial Allocation =  1509, Limit Value = UNLIMITED 
Resource Name = branches, Current Utilization = 0, Max Utilization = 0, Initial Allocation =  1509, Limit Value = UNLIMITED 
Resource Name = cmtcallbk, Current Utilization = 3, Max Utilization = 19, Initial Allocation =  1509, Limit Value = UNLIMITED 
Resource Name = max_rollback_segments, Current Utilization = 14, Max Utilization = 21, Initial Allocation =  1509, Limit Value =  65535 
Resource Name = sort_segment_locks, Current Utilization = 16, Max Utilization = 40, Initial Allocation = UNLIMITED, Limit Value = UNLIMITED 
Resource Name = k2q_locks, Current Utilization = 0, Max Utilization = 0, Initial Allocation =  2744, Limit Value = UNLIMITED 
Resource Name = max_shared_servers, Current Utilization = 0, Max Utilization = 0, Initial Allocation = UNLIMITED, Limit Value = UNLIMITED 
Resource Name = parallel_max_servers, Current Utilization = 0, Max Utilization = 16, Initial Allocation =   40, Limit Value =  3600 
+0

我可以知道你的Oracle版本嗎?因爲我複製並粘貼了代碼,但仍然收到錯誤,ORA-00942和PLS-00364。 – Annon

+0

ORA -00942是表或視圖不存在而PLS-00364是循環索引變量'RL'使用無效。 – Annon

+0

我認爲這是v $ resource_limit問題。我嘗試過與HR.departments並沒有問題。我可以知道上面是使用SYS作爲SYSDBA執行的嗎? – Annon

1

對不起,我不是一個Oracle實例面前更充分地幫助你。但是,我發現c1的聲明沒有任何問題。

但是,您並沒有在您的程序中實際使用c1。你FOR循環應該是:

FOR rl IN (
    select * from v$resource_limit 
) LOOP 

...沒有BULK COLLECT INTO r1

+0

c1是否在最初的聲明部分中使用? – Annon

+0

你不需要爲你的'FOR ... LOOP'聲明'c1','rl_typ'或'rl'就像書面一樣工作(如果你拿出'BULK COLLECT',就像我之前說過的那樣)。 –

+0

謝謝。但是程序編譯在ORA-00942和PLS-00364中仍然存在錯誤。 – Annon

0

grant select any dictionary to that particular user;或者如果你只想給v $ resource_limit權限,那麼grant select on v$resource_limit to particular user; 然後嘗試

+0

授權選擇任何字典給人力資源部門。謝謝。 – Annon