1

我需要以下输出

  • 队列名称:队列的名称
  • 状态:0 就绪,1 等待,2 已处理,3 已过期 - 队列表
  • 计数:统计该状态的队列表中的记录数。

例子

Queue Name         State         Count
---------------------------------------
Email_Q            Processed      5939
Email_response_Q   Waiting         133

我构造了以下SQL

SELECT 'select ''' || owner || '.' || name || ''' queue_name, 
        decode(state,0,''Ready'',1,''Waiting'',2,''Processed'',3,''Expired'',''?'') state, 
        count(*) count 
        from ' || owner || '.' || queue_table || 
        ' where q_name = ''' || name || ''' group by state' cmd
  FROM all_queues
 WHERE owner IN ('AMADEUS')
 ORDER BY owner, name; 

我能够为 Queue 表构建所有选择。但我想使用 select 语句获取输出。

我在考虑管道功能或使用全局临时表。任何帮助都感激不尽。

4

1 回答 1

0
DECLARE
   sqlStr VARCHAR2(2000);
BEGIN

   dbms_output.put_line(RPAD('queue_name',30,' ') || RPAD('State',30,' ')  || LPAD('Count',30,' ') );             
   FOR rec_ IN ( SELECT 'select ''' || OWNER || '.' || NAME ||
                        ''' queue_name,          decode(state,0,''Ready'',1,''Waiting'',2,''Processed'',3,''Expired'',''?'') state,          count(*) count          from ' ||
                        OWNER || '.' || QUEUE_TABLE || ' where q_name = ''' || NAME ||
                        ''' group by state' CMD
                 FROM ALL_QUEUES
                 WHERE OWNER IN ('AMADEUS')
                 ORDER BY OWNER, NAME               
               ) LOOP
      sqlStr := 'BEGIN
                    FOR rec_ IN (' || rec_.cmd ||
                                 ') LOOP
                       dbms_output.put_line( RPAD(rec_.queue_name,30,'' '') || RPAD(rec_.State,30,'' '')  || LPAD(rec_.Count,30,'' '') );   
                    END LOOP;
                 END;';
      EXECUTE IMMEDIATE sqlStr ;
   END LOOP;   
END;                            
于 2012-08-13T09:32:09.323 回答