1

I need the following output

  • Queue Name: Name of the queue
  • State: 0 Ready,1 Waiting, 2 Processed, 3 Expired - of the queue table
  • Count: count the number of records in the queue table of that state.

Example

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

I constructed the following 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; 

I am able to construct all the selects for the Queue tables. But I would like to get the output using a select statement.

I was thinking of pipeline functions or use of a global temporary tables. Any help will be much appreciated.

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 に答える