In Oracle APEX Classic Reports, column headings are usually static — but sometimes, we need them to change dynamically based on user input.
Using the “PL/SQL Function Body” option under the Heading attribute, we can generate report column names at runtime.
This approach provides flexible and context-driven report labels without manual modification.
In this setup, a page item holds a range value (e.g., A1-A7 or H1-H7).
A PL/SQL function reads that range and constructs the column headings dynamically (like A1:A2:A3:A4:A5:A6:A7).
These values are then applied automatically to the Classic Report’s columns through the PL/SQL Function Body returning VARCHAR2 attribute.
Paste the following code in the Classic Report attributes section under the Heading property
DECLARE
v_start NUMBER;
v_end NUMBER;
v_prefix VARCHAR2(10);
v_result VARCHAR2(4000);
BEGIN
v_prefix := SUBSTR(:P22_LABEL_VALUE, 1, 1);
v_start := TO_NUMBER(SUBSTR(:P22_LABEL_VALUE, 2, INSTR(:P22_LABEL_VALUE, '-') - 2));
v_end := TO_NUMBER(SUBSTR(:P22_LABEL_VALUE, INSTR(:P22_LABEL_VALUE, '-') + 2));
FOR i IN v_start .. v_end LOOP
v_result := v_result || v_prefix || LPAD(i, 2, '0') || ':';
END LOOP;
RETURN RTRIM(v_result, ':');
END;
NOTE: The above code is written to accept input in the format CHR||NUM-CHR||NUM. If you need a different format, modify the code accordingly.
Comments
Post a Comment