Are the error codes always going to be in order? You ought be able to utilize a connect by in that case as such:
SELECT COUNT(MY_TABLE.ERROR_CODE) || ',' || ERROR_CODES.error_code as amount_and_code
FROM
(
SELECT (5000+LEVEL) error_code
FROM DUAL
CONNECT BY LEVEL <= 5
) ERROR_CODES
LEFT JOIN
(
SELECT 5001 ERROR_CODE, (SYSDATE - 1/26) ENTRY_DATE FROM DUAL
UNION ALL
SELECT 5001 ERROR_CODE, (SYSDATE - 1/26) ENTRY_DATE FROM DUAL
union all
SELECT 5001 ERROR_CODE, (SYSDATE - 1/26) ENTRY_DATE FROM DUAL
union all
SELECT 5001 ERROR_CODE, (SYSDATE - 1/26) ENTRY_DATE FROM DUAL
union all
SELECT 5002 ERROR_CODE, (SYSDATE - 1/26) ENTRY_DATE FROM DUAL
union all
SELECT 5005 ERROR_CODE, (SYSDATE - 1/26) ENTRY_DATE FROM DUAL
UNION all
SELECT 5005 ERROR_CODE, (SYSDATE - 1/26) ENTRY_DATE FROM DUAL
) MY_TABLE
ON MY_TABLE.ERROR_CODE = ERROR_CODES.ERROR_CODE
AND MY_TABLE.ENTRY_DATE >= (SYSDATE - 1/24)
GROUP BY ERROR_CODES.ERROR_CODE
order by ERROR_CODES.error_code
;
if you simply want to show all errors you can try this
with MY_TABLE as(
SELECT 5001 ERROR_CODE, (SYSDATE - 1/26) ENTRY_DATE FROM DUAL
UNION ALL
SELECT 5001 ERROR_CODE, (SYSDATE - 1/26) ENTRY_DATE FROM DUAL
union all
SELECT 5001 ERROR_CODE, (SYSDATE - 1/26) ENTRY_DATE FROM DUAL
union all
SELECT 5001 ERROR_CODE, (SYSDATE - 1/26) ENTRY_DATE FROM DUAL
union all
SELECT 5002 ERROR_CODE, (SYSDATE - 1/26) ENTRY_DATE FROM DUAL
union all
SELECT 5005 ERROR_CODE, (SYSDATE - 1/26) ENTRY_DATE FROM DUAL
UNION ALL
SELECT 5005 ERROR_CODE, (SYSDATE - 1/26) ENTRY_DATE FROM DUAL
UNION ALL
SELECT 5003 ERROR_CODE, (SYSDATE - 1/23) ENTRY_DATE FROM DUAL
UNION ALL
SELECT 5004 ERROR_CODE, (SYSDATE - 1/23) ENTRY_DATE FROM DUAL
UNION ALL
SELECT 5006 ERROR_CODE, (SYSDATE - 1/23) ENTRY_DATE FROM DUAL
UNION ALL
SELECT 5010 ERROR_CODE, (SYSDATE - 1/23) ENTRY_DATE FROM DUAL
UNION ALL
SELECT 6018 ERROR_CODE, (SYSDATE - 1/23) ENTRY_DATE FROM DUAL
)
SELECT COUNT(MY_TABLE.ERROR_CODE) || ',' || ERROR_CODES.error_code as amount_and_code
FROM
(
SELECT DISTINCT ERROR_CODE
FROM MY_TABLE --**warning** this could be resource intensive
) ERROR_CODES
LEFT JOIN
MY_TABLE
ON MY_TABLE.ERROR_CODE = ERROR_CODES.ERROR_CODE
AND MY_TABLE.ENTRY_DATE >= (SYSDATE - 1/24)
GROUP BY ERROR_CODES.ERROR_CODE
order by ERROR_CODES.error_code
;
This is really just giving you a distinct on all the error codes in the table then selecting the count based off of time
(
SELECT DISTINCT ERROR_CODE
FROM MY_TABLE --**warning** this could be resource intensive
) ERROR_CODES
please note, this can be resource intensive
if you only want specific numbers (that is 5001,5002,5003,####,####2,...,###x) then you can try something like this (this requires a custom type and a function to be created):
--see http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:210612357425
--create a table of numbers ,create a function to split the "where" into a table
--then return the data
CREATE OR REPLACE type numberTableType as table of number;
/
create or replace function in_number( p_string in varchar2 ) return numberTableType AS
l_string long default p_string || ',';
l_data numberTableType := numberTableType();
l_number number ;
N NUMBER;
BEGIN
loop
exit when l_string is null;
n := instr( l_string, ',' );
l_data.extend;
begin --is user inputs a non-numeric value skip the value
l_number := cast(ltrim( rtrim( substr( l_string, 1, n-1 ) ) ) as number);
l_data(l_data.count) := l_number ;
EXCEPTION
WHEN VALUE_ERROR THEN
l_number := 0;
WHEN OTHERS THEN
raise ;
end ;
l_string := substr( l_string, n+1 );
end loop;
RETURN L_DATA;
END in_number;
/
SELECT COUNT(MY_TABLE.ERROR_CODE) || ',' || ERROR_CODES.error_code as amount_and_code
FROM
(
SELECT COLUMN_VALUE AS ERROR_CODE
from table(in_number('5001,5002,5003,5004,5005,5010'))
) ERROR_CODES
LEFT JOIN
(
SELECT 5001 ERROR_CODE, (SYSDATE - 1/26) ENTRY_DATE FROM DUAL
UNION ALL
SELECT 5001 ERROR_CODE, (SYSDATE - 1/26) ENTRY_DATE FROM DUAL
union all
SELECT 5001 ERROR_CODE, (SYSDATE - 1/26) ENTRY_DATE FROM DUAL
union all
SELECT 5001 ERROR_CODE, (SYSDATE - 1/26) ENTRY_DATE FROM DUAL
union all
SELECT 5002 ERROR_CODE, (SYSDATE - 1/26) ENTRY_DATE FROM DUAL
union all
SELECT 5005 ERROR_CODE, (SYSDATE - 1/26) ENTRY_DATE FROM DUAL
UNION ALL
SELECT 5005 ERROR_CODE, (SYSDATE - 1/26) ENTRY_DATE FROM DUAL
UNION ALL
SELECT 5003 ERROR_CODE, (SYSDATE - 1/23) ENTRY_DATE FROM DUAL
UNION ALL
SELECT 5004 ERROR_CODE, (SYSDATE - 1/23) ENTRY_DATE FROM DUAL
UNION ALL
SELECT 5006 ERROR_CODE, (SYSDATE - 1/23) ENTRY_DATE FROM DUAL
UNION ALL
SELECT 5010 ERROR_CODE, (SYSDATE - 1/23) ENTRY_DATE FROM DUAL
UNION ALL
SELECT 6018 ERROR_CODE, (SYSDATE - 1/23) ENTRY_DATE FROM DUAL
)
MY_TABLE
ON MY_TABLE.ERROR_CODE = ERROR_CODES.ERROR_CODE
AND MY_TABLE.ENTRY_DATE >= (SYSDATE - 1/24)
GROUP BY ERROR_CODES.ERROR_CODE
ORDER BY ERROR_CODES.ERROR_CODE
;