Mobile Applications with APEX & jQuery Mobile

Mobile development is not the next big thing anymore, it is THE big thing today. And as you may already know, Oracle APEX is ready to take on the challenge of creating mobile business solutions.

We at iAdvise already started to experiment with mobile application development in APEX 4.0, but off course this was not the ideal environment yet. Since APEX 4.1 you can declaratively create mobile applications with jQuery mobile, and with the latest release (4.2) it’s really starting to lift off. You can even declaratively build responsive applications.

In May 2012 we gave a seminar about mobile development, and since then we successfully developed several mobile solutions for our clients. Below you can find a demo of an application we created for one of our most valued customers, New Holland Tractor Ltd.

New Holland Tractor Ltd

About New Holland: Since 1895, New Holland is committed to providing solutions that improve farming efficiency and productivity.
New Holland offers cash crop producers, livestock farmers, contractors, vineyards and groundcare professionals the largest choice of easy-to-operate tractors, harvesters and material handling equipment.

New Holland complements the widest agricultural equipment offering in the world with efficient Parts and Service support and a range of tailored financial services from a specialist in agriculture. Setting themselves the highest standards in quality and service, is part of the culture of New Holland, part of the DNA of New Holland. The plant in Antwerp (New Holland Tractor Limited) with some 1,000 employees, is a major manufacturing unit of tractor parts such as rear axles and drive systems.

Mobile application

New Holland Tractor requested a mobile solution to let their workers use checklists at the quality gates of the assembly lines in the plant.
In the past they had to manage all these checklists by hand. For each checklist, a paper form had to be filled out after which it had to be processed by hand. This created a lot of overhead and it was very easy to make errors.

The application had to be developed in Oracle APEX 4.1 and had to be super user-friendly. The result is a simple, yet elegant application.


At iAdvise we invest a lot to make our applications user-friendly. For this project we started off by designing mockups that were used as guidelines during the development phase, those helped us to create a very simple and efficient application.

For the workers of New Holland Tractor, this solution was a huge improvement. Now that the checklists are processed automatically, it’s very easy to analyze the production process and there’s less room for errors, hence it further increased both productivity and efficiency at the assembly lines.

We feel that mobile development with APEX is really kicking off and the APEX development team is on the right track to make APEX a mobile enabled development environment.

Exciting times are coming!

Apex Extension

About a month ago I saw a mail coming by where a colleague of mine had integrated the jQuery plug-in Codemirror into a text area for the end-user. I hadn’t seen this plug-in before, but I really liked the feel of it.

I’m sure all of us can recognize the fact that we miss tab indentation in  APEX, or that we would like to see key words, numbers and strings in color, or how about some line numbers? Perhaps line numbers that hold into account that the line number of an error in a PL/SQL APEX process is never quite the same as the place of the error. This last one is because APEX places BEGIN and END; automatically around PL/SQL processes. Convenient for the developer so he can develop faster, not so much when it comes down to debugging.

Since we can not change the APEX Application Builder, it would be nice to find another solution? And that solution exists: take a look at the following screenshots:



So how did I do it? A little “thinking outside the box” did the trick. While we might not want to mess with Apex directly, we can use browser Extensions and add-ons, to alter the looks, safely from a distance. So I created a small Chrome Extension that integrates CodeMirror into the APEX Text Areas.

Chrome Extensions are created with HTML5 and JS so once you have the basics of your Extension set up you can convert an Apex Text Area like this:
var vTextArea=document.getElementById(“F4000_P4312_PROCESS_SQL2″);

vMyEditor = CodeMirror.fromTextArea(vTextArea, {

mode: “text/x-plsql”,
tabMode: “indent”,
tabSize : 2,
lineNumbers: true,
firstLineNumber: 2,
lineWrapping: true

I wrapped this in a “$(document).ready(function(){});” to make sure it is executed after loading all plug-ins.

I hope I showed you all that you can do allot with a little imagination, and I welcome any questions or suggestions.

Joni Vandenberghe

Using a database link with heterogeneous services in APEX

Last weeks I ran into some issues with APEX, so let’s take some time to write something about them.

The most recent is about heterogeneous services (also referenced as HS). Here is the case:
We have an Oracle DB instance with some APEX applications and in one of those applications I need data from a MS SQL server database. Not a very good idea, but the set-up couldn’t be changed and both databases can handle it, so I gave it a try.

Our DBA installed heterogeneous services and created a database link between the two databases. Querying the necessary views was pretty easy (I only needed a couple of synonyms for ease of maintenance) and data came in faster than expected.

The next step was to query these views with APEX.
Because I created Oracle views on the views of MS SQL server, this was also very straightforward for APEX.

After a while however, there were issues in other applications and also the APEX builder itself raised errors while uploading files and importing applications. The following error returned:

ORA-02047: cannot join the distributed transaction in progress

, usually accompanied by some other ORA error codes. Not a very descriptive error message. A colleague pointed out to me that it has something to do with database links and heterogeneous services.

So, what is the problem?
APEX starts a new database session for my application. In this session the database link to the MS SQL server database is opened and data is queried. Since APEX constantly changes and re‑uses database sessions (this technique is called session pooling), the database session is released after a while and put back in the session pool until another application needs a new/another session. Because the database link in my session is only used for querying, there is no line of code that closes the database link so it remains open, even when the session is put back into the session pool. When another application takes this session from the pool, there might be issues with specific transactions, like setting a context (e.g. setting NLS parameters), because Oracle wants to perform this operation on both the Oracle database and the linked MS SQL server database. Because an NLS parameter is set when uploading a file, the end user receives the ORA-02047 error.

What can one do to prevent this from happening? There are several solutions for this issue:

  1. Don’t use database links with heterogeneous services. This is the easiest solution but isn’t always possible.
  2. Only access data over a DB link with HS in a package, function, procedure,… and close the DB link at the end of your block of code, which is not always possible either.
  3. Close any open database link, or only the specific one, when you put your session back into the session pool.

For the third solution, something interesting is implemented in APEX 4.1.

At application level, you can define some PL/SQL code that should be executed when initializing or returning a session from/to the session pool.

You can find this section under Shared Components  >  Security Attributes. All the way at the bottom is the section ‘Database Session’:

In earlier versions of APEX, something similar was already available for VPD (Virtual Private Database) but this only allowed execution of code at session initialization. The APEX development team has now expanded this functionality for any PL/SQL in general, so not only VPD-related, and both at session initialization and returning.

For my issue, all I had to do was write some code to close the database link when it was still open. I created a function in my application database schema which returns the number of open database links with a specified name:

CREATE FUNCTION is_dblink_open(dblink  IN VARCHAR2)
  l_cnt   INT;
  SELECT COUNT(db_link) INTO l_cnt
  FROM v$dblink
  WHERE db_link = dblink;
  RETURN l_cnt;
    RETURN 0;

Before you create this function, don’t forget to grant access to v$dblink:

GRANT select ON v_$dblink TO my_app_schema;

Execute with SYS. Note the v_$ instead of v$! (more info:

All that was left is to use this function in the Database Session Clean Up Code:

  l_dblink VARCHAR2(100) := 'MY_SQL_SRV_DBLINK';
  IF is_dblink_open(l_dblink) > 0 THEN

Or if you want to be sure that all open database links are closed, you could use:

  FOR l_db_link IN ( SELECT db_link AS name FROM v$dblink ) LOOP

Special thanks to my colleague Jan for pointing out to the HS problem and to Patrick Wolf for helping me on this issue through the Oracle APEX forum (read the full post here:

This way, I hope to help out other people too when they run into this issue.