我需要以下输出
实施例
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语句获取输出。
我在考虑管道功能或使用全局临时表。 任何帮助将不胜感激。
答案 0 :(得分: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;