When you have a classic report in Oracle Application Express (APEX) and want to make it searchable you typically add a Text Item in the region, enable Submit on Enter and add a WHERE clause to your SQL statement.
Here’s an example:
Your SQL statement probably looks like this:select CUSTOMER_ID,
When you want to search for multiple customers separated by a comma, how do you do that?
So in my search field I add for example: 1,2,3 and expect to see 3 customers.
There’re a couple of options you have, I’ll list three below:
INSTRwhere INSTR(','||:P4_SEARCH||',', ',' || CUSTOMER_ID || ',') > 0
REGEXP_LIKEwhere REGEXP_LIKE(CUSTOMER_ID, '^('|| REPLACE(:P4_SEARCH,',','|') ||')$')
REGEXP_SUBSTRwhere customer_id in to_number((
Which one to choose? It depends what you need… if you need readability, maybe you find INSTR easier to understand. If you need performance, maybe the last option is the better choice… so as always it depends. If you want to measure the performance you can look at the Explain Plan (just copy the SQL in SQL Workshop and hit the Explain tab).
The Explain Plan for the first SQL looks like this:
The Explain Plan for the last SQL looks like this:
The above technique is also useful when you use want checkboxes above your report, so people can make a selection. For example we select the customers we want to see:
The where clause would be identical, but instead of a comma (,) you would use a colon (:), so the first statement would be:where INSTR(':'||:P4_SEARCH||':', ':' || CUSTOMER_ID || ':') > 0
Happy searching your Classic Report :)
When reviewing Oracle APEX applications I often see hardcoded date or timestamp formats.
You can define your date formats in multiple places in your application. In your item or column attributes, as part of your code e.g.TO_CHAR(sysdate, ‘DD-MON-YYYY HH24:MI’) or if you want to make it more reusable you might create a substitution string. That will all work, but you can make your life easier and for the ones looking or needing to maintain your code…
APEX itself provides in the Globalization attributes (Shared Components) a place where you can define your default date and format masks for your entire applications. I consider this a best practice to use those fields, as it’s defined in one logical place, so when you need to change your format, you do it once and you’re done. In your custom SQL and PL/SQL code you can also reference those format masks by predefined substitution strings:
e.g. TO_CHAR(sysdate, :APP_NLS_DATE_FORMAT)
Here’s a screenshot which shows which substitution string corresponds with which field:
You can define the format mask you want, or you can click the arrow to see most used format masks represented with an example. To make it a bit easier, I put the format mask (in red) next to it, so you see the underlying format mask more easily:
If you need to make the format mask dynamic, for example using different format masks for different language, APEX doesn’t allow you to translate that substitution string through Text Messages, but you can work around it by using your own substitution string and have that dynamically filled. In the Globalization Attributes you would add instead of a hardcoded format mask your own substitution string e.g. &MY_TRANSLATED_DATE.FORMAT.
Today I got the question how to change the label of an item in Oracle Application Express (APEX) based on some condition. I actually had this requirement myself a couple of times, so maybe other people too.
Here’s an example; whenever we change the Source item, we want the Affected Item to change it’s label:
The first thing that comes to mind (if you already know a little bit of APEX); lets use a Dynamic Action: on change of the Source item we will fire (in this example we will only fire when the value is A):
Now which action should we use when the dynamic action fires?
Set Value will typically set the value of an Item, but what about the Label?
This will set the label to "My new label for " and then the value of the item, at least if you select in the Affected Elements the item that needs the label change.
Whenever I think about writing custom code, my mind says “you should create a plugin for that”.
So I actually started to write an Oracle APEX Plug-in called “Set Label” (https://github.com/dgielis/orclapex-plugin-set-label)
While I was trying the plugin and writing up the things I needed to do, I guess something happend in my mind. I missed the obvious, it suddenly came to my mind there’s a much simpler solution to this…
You can actually use the Set Value action… just add after your item _LABEL, that’s it.
Here’s the result:
Sometimes developing is much more simple than initially thought, you just have to see it :)
I’m trying to write this blog post with classeur.io.
Just like Martin I’m also searching for alternative ways to write blog posts. I don’t want to completely migrate my blog to a new platform, so I’m searching for a way to write in Markdown and deploy to Blogger.
Since our development of APEX Office Print (AOP) we also use Markdown for our documentation as it makes including code samples easier, it can be version controlled and overall it’s pleasant to write in. Whenever we deploy a new version, we publish the markdown as HTML. For example you see the result of our documentation here. SSjj… we like Markdown so much that we are even looking into supporting Markdown to write your template in AOP, next to Word, Excel and Powerpoint, but more on that in the February timeframe. :)
So I’m giving classeur.io a try, it’s just another Markdown editor, but it can publish directly to Blogger. It allows me to include code samples like this:declare
Or if I want to reference somebody I can use a quote:
Oracle Application Express (APEX) changed my life. – Dimitri Gielis
And a list … for example the top 3 reasons I’m looking at a different way to blog:
So this post is really to try the different options of classeur.io which should show up in Blogger after I hit the publish button.
Here’s an image which I plan to use in my next post:
If you see this and the post looks ok, my test went well :)