Custom Authentication Status

When writing custom authentication scheme I noticed that invalid logins weren’t showing up properly in the apex logs (apex_workspace_access_log).

Here’s how to re-create the problem along with the fix.

First let’s create a custom authentication function:

p_username IN VARCHAR2,
p_password IN VARCHAR2
IF LOWER (p_username) = ‘pass’
AND LOWER (p_password) = ‘123’ THEN

Let’s set the APEX authentication scheme to use this custom function:

Shared Components / Authentication Schemes:

  • Create
  • From Scratch
  • Name: BLOG_TEST
  • Keep hitting “Next” until:

    • Credentials Verification Method:
      • return blog_cust_auth
    • Keep hitting “Next” until the end
  • Change the current authentication scheme to BLOG_TEST

    • On the Authentication Schemes page, on the right hand side select “Change Current” and select “BLOG_TEST’

Let’s create a region to always display the authentication statuses:

  • Create Page
    • Page Zero
  • On Page 0 Create a region
    • Report

      SELECT user_name,
      FROM apex_workspace_access_log
      WHERE application_id = :APP_ID
      ORDER BY access_date DESC

      Now let’s try to log in using a valid username and password:
  • username: pass, password: 123

If things worked well you’re now on P1, and the “AUTHENITCATION_RESULT” is flagged as “AUTH_SUCCESS”

Now logout and try to login with invalid credentials

  • username: pass, password: fail

You’ll notice that the login failed, however it still logged it as a successful login attempt:

Let’s update our authentication function to use the 2 authentication result customizations:
apex_util.set_authentication_result and apex_util.set_custom_auth_status

p_username IN VARCHAR2,
p_password IN VARCHAR2
IF LOWER (p_username) = ‘pass’
AND LOWER (p_password) = ‘123’ THEN
– Set APEX authentication Codes
apex_util.set_authentication_result (p_code => 3);
– Set our own APEX custom text
apex_util.set_custom_auth_status (p_status => ‘Bad Username’);

Let’s now see what happens when we now login with invalid credentials:

Notice that we now have proper error information in the logs? Here’s a list of some codes you can use for apex_util.set_authentication_result, taken from the view apex_workspace_access_log:


Of course you can use your own codes but I’d suggest sticking with these codes to utilize the APEX views. You can supplement the codes with the custom authentication status text (apex_util.set_custom_auth_status)

Invalid set of rows requested, the source data of the report has been modified. - Explanation

When I first started using APEX I occasionally got the following pagination error message: Invalid set of rows requested, the source data of the report has been modified. reset pagination

At first I had no clue what was causing the error but after a while I finally figured it out. The best way to describe the error is to see exactly what is happening. Full example is here

Create a report

FROM emp
WHERE UPPER (ename) LIKE '%' || UPPER (:P800_LETTER) || '%'

When creating the report, change the number of rows from 15 to 5 for this example. This is important for this demonstration!

Now create a page item called P800_LETTER and a submit button who submits and redirect to P800.

If things went well you’d have a report that looks like this:

To illustrate the problem click on the Next pagination link so that we are seeing rows 6~10.
Now, in the text box enter the letter I (this will restrict to 4 rows) and click submit. You should see the following error message:

To summarize what just happened, you initially requested a report with 14 rows and told APEX to display 5 at a time. When you clicked the Next pagination button you told APEX for the report you’re currently looking at display rows 6~10. So now, if you were to refresh the page APEX would continue to show rows 6~10. When you filtered the report, by restricting to employees with the letter I in their name, you get a result with only 4 rows however APEX is still trying to display rows 6~10. I hope you now see the problem with this.

So now that we’ve demonstrated the problem, how do you fix it? Well there’s several ways. To solve our current issue, on P800 in the submit branch we could check the reset pagination for this page. This means that each time you submit the page APEX will set the display rows back to 1~5.

There are also other ways to reset the pagination automatically. You can reset pagination in the URL: In the Clear Cache section you can enter RP to clear the page’s cache. Please see the APEX documentation for more information. There is also a page process to reset the pagination. This allows you to also set the scope of the current page, multiple pages, or all pages.

I know the issue has come up to reset the pagination for an individual report rather than the entire page. I currently don’t know of any method, however if you do please post!

q Function: Escape Single Quotes

Last year Scott Spendolini gave our company an excellent 3 day training session on APEX. He also showed us a very nifty function (new in 10g I think) to help not having to escape single quotes when defining strings. This is not APEX specific, however it will help you if you ever have to write a block of PL/SQL to return an SQL statement for reports.

Instead of writing out a long description here’s an example:

v_sql VARCHAR2 (255);
v_result VARCHAR2 (255);
v_sql := ‘select ‘’hello’’ into :a from dual’;

INTO v_result;

DBMS_OUTPUT.put_line (v_result);
Notice how I had to put 2 single quotes around “Hello” to escape the single quote characters?

Now using the q function I don’t need to do that:

v_sql VARCHAR2 (255);
v_result varchar2(255);
v_sql := q’!select ‘hello’ into :a from dual !’;

INTO v_result;

DBMS_OUTPUT.put_line (v_result);
Notice now how “Hello” is wrapped as it would appear if it were not in variable definition function?

This can save you a lot of time by avoiding having to escape single quotes in strings!

Update:  q Function Inside a q Function

Test Data in Production Applications


Well this isn’t an APEX specific post but I thought it should be mentioned either way. It raises a good point about keeping test data out of production.

I got the following email from a colleague today:

I’m a bit of a golf fan, and I like to read up on current events, standings, player profiles, etc. My favorite site to do this is

I was recently searching for a player with the surname of Fischer on the website. I had a good laugh when the search results came back. Take a look at the 6th name in the list in the attached image…“

Here’s the screenshot:

  • Martin

"Application ID Reserved" - Fix

When you upgrade an application do you ever get the following Application ID Reserved error message?

Even if you delete your application and try to re-import using the same application ID you’ll get the message.

To view “reserved” application ids you can run the following query (please note you may need to be a dba user):

select *
from flows_030100.wwv_flows_reserved;

In order to fix this problem you just need to delete the application id from that table:

from flows_030100.wwv_flows_reserved
where id = :p_app_id; -- Your application ID that is locked

APEX Report with checkboxes (advanced).

Note: This solution was updated to account for APEX’s new features and APIs. See the updated post here:

A colleague of mine wanted to build a report with check boxes. Once the user selected all the rows, they would click submit and the application would process the rows. Sounds pretty simple and straight forward however he did have some extra requirements:

  • The report is an interactive report
  • There may be up to 10,000 records in the report
  • When the user “scrolls” through the report (i.e. uses pagination), if they checked off a box it should remain checked the entire time (i.e. if they check an row in the 1st 15 rows, then view rows 16~30, then go back to rows 1~15 it should remain checked)

So here’s the example on how to do it. The working example can be found here:

Create an application item F_EMPNO_LIST. Note you can use a page item as well…

Setup IR:

SELECT apex_item.checkbox (1,
) checkbox,
empno, ename, job
FROM emp

Once the report is setup set the row display to 5 (you’ll need it for this example)

  • Add an HTML region and add the following code: (Note: the jQuery call is not needed… for now)

    CHECKBOX List:


    Now create an application process (on Demand) called: CHECKBOX_CHANGE

    – Application Process: CHECKBOX_CHANGE
    – On Demand…

    v_item_val NUMBER := apex_application.g_x01;
    v_checked_flag VARCHAR2 (1) := apex_application.g_x02;
    IF v_checked_flag = ‘Y’ THEN
    – Add to the list
    IF :f_empno_list IS NULL THEN
    :f_empno_list := ‘:’ || v_item_val || ‘:’;
    :f_empno_list := :f_empno_list || v_item_val || ‘:’;
    END IF;
    – Remove from the list
    :f_empno_list := REPLACE (:f_empno_list, ‘:’ || v_item_val || ‘:’, ‘:’);
    END IF;

    – Just for testing
    HTP.p (:f_empno_list);

    • On the post page create a query to view data (you can process how you need/want)

      select *
      from emp
      where instr(:F_EMPNO_LIST, ‘:’ || empno || ‘:’) > 0

      Please note there may be better/faster ways to implement the SQL code etc.

    Here are some links on the x01 code that I used: and

How to access images in APEX on Linux


Dietmar has a great post on where the images are located in APEX using webdav: He also covers how to access them via FTP!

I recently switched from Windows to Linux and was looking for a quick way to access the files as I would with Windows.

Using KDE and Konqueror, you can access them very easily. Use the following in the URL: webdav://<url>

So it would be: webdav://

Log in with system and you should be able to access everything!


jQuery Calendar and Application Date Format


Last week Roel had a posting about jQuery’s Date Picker: Definitely a great example for people who are looking for an alternative to APEX’s date picker.

We do use the jQuery calendar and have some interesting standards around it (I’ll try to blog about this another day). The most important one, and easiest to implement, is the date format standards.

Javascript/jQuery and Oracle use different date formats. If you are going to use the jQuery date picker I strongly suggest that you standardize your date formats so that you won’t have conflicting results down the road. Here’s what we do:

We have 2 application level items:

F_DATE_FORMAT: is used for the application level date format
F_JQUERY_DATE_FORMAT: format to display the date the same as f_date_format

Both these items are set at login time and the values are defined in our database at the client level. You have to make sure that the date formats produce the same results.

In Roel’s example he uses the jQuery on load function. For the date format just use &F_JQUERY_DATE_FORMAT. instead and this will load set the jQuery date formats accordingly.

Here’s a listing of jQuery’s date formats:

And Oracle’s date formats:

Hope this helps,


How to list APEX Dictionary views using SQL


I hope this isn’t old news but it seems that whenever someone talks about the APEX dictionary they talk about going into the development application and viewing them there. You can also access the dictionary using SQL. Here’s how:

select *
from apex_dictionary
where column_id = 0


select distinct apex_view_name
from apex_dictionary

Of course you can remove the “where column_id=0” portion and get a list of the all the columns for the views etc.

CSS Specificity

Most APEX developers will eventually get asked to brand their application or “make it look nice”. If you are like myself, and are not a graphic artist, this can be quite a challenge since it is an art to make a web pages look really good.

I’ve had to do read up on it over the past few months. I finally read an article on CSS specificity (try say that 5 times in a row :-). CSS Specificity is like putting a score or weight on each CSS definition so you know which ones will “override” other definitions.

Here’s the article:

There’s also a link to the CSS specificity calculator: