I'm currently trying to create a dynamic action inside of Oracle APEX using a PL/SQL script that counts the amount of Yes and N/A responses in a table and return a percentage of the progress towards every cell being a Yes or N/A. Since the table is pretty large I was thinking that putting all of the column headers into an array and running the select statement in a for loop would be the most efficient way to do this. Here is what I have so far:
DECLARE
type array IS VARRAY(20) OF VARCHAR2(1000);
columns_array array := array('...','...',...);
arr_Size number(4, 2) := 20;
Counter number(5, 2);
Progress number(5, 2);
BEGIN
FOR i in 1..arr_Size
LOOP
select COUNT(columns_array(i))
into Counter
from Table
where array(i) = 'Yes' OR array(i) = 'N/A';
Progress := Progress + Counter;
END LOOP;
END;
The program compiles without any errors but the code outputs zero for progress after running when it shouldn't. I think the problem is that I used an array inside of the select statement, but I don't know any other way to accomplish what I'm trying to do.
...in the array elements - column names? Your code is comparing the element values with Yes or N/A - it is interpreting the array values as literals strings, not treating them as columns, if that is what you are trying to do. You would need to use dynamic SQL if the column you're referring to isn't a fixed value. With a fixed list of column names it would probably be easier to just do repeated conditional aggregation.arr_Size number(4,2) := 20;Why the two decimal places?20seems like an integer. And why not declare arr_Size first as a constant and use it as the array size, instead of repeating '20' in two places?