conditional links in Oracle APEX reports

Conditional links in Oracle APEX reports

Introduction

What most developers should know—but still often don’t practice—is how to create conditional links in their reports. It often happens that a link should only be displayed under certain conditions, and otherwise not at all. What 90% of developers then do is create the link on the fly within the SQL statement using apex_page.get_url.

Things get even more complicated when, instead of a normal page, a modal dialog needs to be opened. That’s a valid approach, but it’s rather inelegant—and, above all, unnecessary.

We’d like to remind you that in Oracle APEX, there are other ways to achieve an equally good solution with less code.

Below, we’ll describe the steps required to do so.

Solution

Let’s assume, this is our Report Query

				
					SELECT
    NULL link,
    CASE WHEN deptno IN (20, 30) THEN '<span class="fa fa-edit"></span>'
        ELSE NULL END condition,
    deptno,
    dname,
    loc
FROM
    dept

				
			

We define two columns — a link column and a condition column. The condition column generates an image based on the specified condition.

After creating the report, we make the following adjustments:
Set the CONDITION column type to Hidden, and disable “Escape special characters” Option.

For the Link column, define it as a link and configure the target page as you normally would for any link.

Under the Link Text property of the column, enter #CONDITION# to display the image whenever the condition is met.

As a result of these adjustments, the links are now displayed in our report for department numbers 20 and 30, and not shown for the other numbers.

Conclusion

With this approach, we’ve demonstrated how to create conditional links in Oracle APEX reports without embedding complex link logic directly into the SQL query. By separating the link and condition into two dedicated columns, we achieve a cleaner, more maintainable design.

This method not only reduces code complexity but also improves flexibility — the visual indicator (icon or image) appears only when the defined condition is met, and the underlying link behavior remains fully configurable through the APEX UI.

In short: less code, more clarity, and a professional result that aligns perfectly with APEX best practices.

You can access our examples using the following link:

Add a Comment

Your email address will not be published. Required fields are marked *