Solving the APEX PL/SQL Dynamic Content Region Partial Page Refresh Problem

Search for a command to run...

"One thing I should add at this point is that my dynamic content is made up of several CLOB fields containing HTML content (including images). This content can get much larger than the 32,767 byte limit for a VARCHAR2 field type." Could you please explain this part, I am facing an issue in the PL/SQL Dynamic Content Region if the content exceeds 32,767 bytes. I am getting errors. How do we resolve this issue?
Are you having the error while building the CLOB in the collection or when the Classic Report is trying to render the CLOB column? If it is the latter, it may be that your version of APEX does not support a CLOB in a report column. Try using the FOS PL/SQL Dynamic Content Region plugin to render the HTML https://apex.world/ords/f?p=100:710:16028002025145::::P710_PLG_ID:COM.FOS.PLSQL_DYNAMIC_CONTENT If you are on APEX 22.2 or later, use the new native Dynamic Content Region https://blog.cloudnueva.com/apex-222-dynamic-content-regions
Introduction One of the marquee features of APEX 26.1 was AI Interactive Reports. When I started testing this new feature, I was interested to see what was going on behind the scenes. In this post, I

Introduction One of the marquee features of APEX 26.1 is APEX AI Agents. APEX AI Agents allow you to use an LLM and your own PL/SQL and JS tools to perform actions on your data instead of just chattin

Introduction In my previous post, I looked at logging APEX AI Agent requests and responses with Request and Response handlers. Logging is the first step because it shows you what is actually moving th

Introduction Logging is one of the first things you need when building serious AI Agents. Without it, debugging quickly becomes guesswork. You can see the final answer, but not always why the model ch

Context management patterns from building agents in Oracle APEX

Every so often, perfectly valid requirements lead you down a path in APEX that you wish you didn't have to follow. I was recently presented with such a requirement, which forced me to create a 'PL/SQL Dynamic Content' region so that I could dynamically build the HTML content for the region myself. This makes me uneasy for two reasons:
Basic Requirement
In this post, I'll describe the problem, a well-known workaround from Scott Spendolini (that didn't work in this case) and the solution that I came up with.
Here is an example of refreshing a report region that supports partial page refresh PPR. You have a Classic Report with a link that opens a modal to edit the content of the row. The user closes the modal and wants the report to refresh automatically without submitting the whole page. This is easily achieved by creating a Dynamic Action in the report page (like the below), which fires on 'Dialog Closed'.

When the modal closes, the dynamic action fires and refreshes just the report region and not the whole page. This is thanks to the fact that Classic Reports have the 'Partial Page Refresh' attribute.

Unfortunately, PL/SQL Dynamic Content Regions do not have the 'Partial Page Refresh' attribute. The only (Low Code) way to refresh this region type after closing a modal is to change the dynamic action (Action) to 'Submit Page'. This will then refresh the entire page which is pretty unsatisfactory from a user experience perspective.
One thing I should add at this point is that my dynamic content is made up of several CLOB fields containing HTML content (including images). This content can get much larger than the 32,767 byte limit for a VARCHAR2 field type.
A number of years ago, Scott Spendolini came up with an ingenious solution which is outlined in his Blog Post. It essentially involves creating a Classic Report with a SELECT statement which calls a function to build and return the HTML content.
SELECT example_pk.generate_html (p_id => :P10_ID) html_content
FROM sys.dual;
Now that the content is coming from a Classic Report (which supports PPR) you can refresh it using the 'Refresh' action of a Dynamic Action.
The problem is that this approach only works if you return a VARCHAR type from the function. If you attempt to return a CLOB, you get the following error:
ORA-00932: inconsistent datatypes: expected - got CLOB
This is unfortunate because if you base a Classic Report column directly on a CLOB column from a table then it handles CLOB content just fine.
My solution involves three components:
I created a Before Header Process in the APEX page, which calls a PL/SQL procedure to Generate the HTML content and add it to the clob001 column in APEX Collections. The logic for the PL/SQL procedure went something like this:
DECLARE
l_return_html CLOB;
BEGIN
-- Code to build up the dynamic content of l_return_html.
l_return_html := l_return_html || TO_CLOB(<<content1>>);
l_return_html := l_return_html || TO_CLOB(<<content2>>);
..
-- Create the Collection.
apex_collection.create_or_truncate_collection(p_collection_name => 'REVIEW_ACTIVITIES');
-- Add a collection record, populatingn the CLOB column with the dynamic content.
apex_collection.add_member (p_collection_name => 'REVIEW_ACTIVITIES', p_clob001 => l_return_html);
END;
I created a Classic Report Region based on a SQL statement which selected just the CLOB content from the apex_collections table:

Region Attributes
Column Attributes

I created a Dynamic Action with and Event of 'Dialog Closed'.
The dynamic action then fired two Actions. The first called the PL/SQL procedure I mentioned above to re-build the dynamic content and update the CLOB column in the APEX Collection:
Then a second Action refreshes the Classic Report Region:

Ideally, PL/SQL Dynamic Content regions should allow Partial Page Refresh and none of the above would be necessary. Unfortunately, 7 years on from Scott's solution, we are still left with workarounds. Hopefully this approach offers a workaround for CLOB content that will get you by until it does become part of the product.
There is hope. It looks like there is an APEX idea for this that is planned for APEX 22.2