I need to create a procedure to validate number of digits between 2 columns. I have some reason that this handling won't do in Java so it needs to be a stored procedure.
It first will get the template(result_format)
from one of my table and itself contain data like
5,5,5,5,5,5,5,5,5,5,4,4,4,4,4,4,4,4,4,4,3,3,3,2,2,2,2
then the argument P_RESULT
will have input like
16768,74300,56212,38614,12250,52274,73018,32467,12618,48801,4257,6831,5436,4757,9395,5294,3687,3408,2803,1680,848,695,479,81,58,28,27
then I need to compare and count the first data from first result [16768] to the result_format [5] to see whether it contains 5 digits as per the result_format, then continue till end of the result. if it detect different in the length of the result to the result format it will throw exception.
My procedure is below, it has compilation errors, it's because of it can't search my temporary table when i trying to put them into a temporary table and start my validation. [line 28]
create or replace procedure RESULT_VALIDATION(P_LOTTERY VARCHAR2,
P_RESULT VARCHAR2 ) as
V_TEMPLATE VARCHAR2(10 BYTE);
V_RESULT RESULTS.RESULT%TYPE;
V_RESULT_FORMAT VARCHAR2(100);
BEGIN
SELECT TEMPLATE INTO V_TEMPLATE FROM LOTTERYS WHERE ID = P_LOTTERY;
BEGIN
SELECT RESULT_FORMAT INTO V_RESULT_FORMAT FROM LOTTERYS WHERE ID = V_TEMPLATE;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RETURN;
END;
execute immediate '
CREATE PRIVATE TEMPORARY TABLE ORA$PTT_RESULT_VALIDATION (
results INT,
formats INT
)
ON COMMIT DROP DEFINITION ;
';
INSERT INTO ORA$PTT_RESULT_VALIDATION(results, formats)
select a.results, b.formats from (
select distinct rownum idx, regexp_substr(P_RESULT, '[^,]+', 1, LEVEL) results from dual
connect by regexp_substr(P_RESULT, '[^,]+', 1, level) is not null order by idx
) a full join
(
select distinct rownum idx, regexp_substr(V_RESULT_FORMAT, '[^,]+', 1, LEVEL) formats from dual
connect by regexp_substr(V_RESULT_FORMAT, '[^,]+', 1, level) is not null order by idx
) b on a.idx = b.idx order by b.idx;
begin
for i in (select * from ORA$PTT_RESULT_VALIDATION) loop
if REGEXP_COUNT(i.results, '\d') != i.formats then
commit;
RAISE_APPLICATION_ERROR (
num => -20000,
msg => 'Invalid Result Format');
end if;
end loop;
end;
commit;
END RESULT_VALIDATION;
is there any workaround that i can do something like this. or maybe not by the method of temporary table?