ODTUG APEXposed 2012

What more is there to say? This event is going to be fantastic and there’s still time to register!

ODTUG APEX Plug-In Competition

As Martin has already announced, there is a very exciting APEX Plugin Competition hosted by ODTUG.

Here’s the official announcement (taken from the ODTUG page):

ODTUG is holding its first ever world wide APEX Plug-ins competition! This is your opportunity to write an APEX plug-in and have it viewed by the entire international APEX community and maybe crowned 2012 ODTUG APEX Plug-in Developer of the Year! Even better, there are some really great prizes with the grand prize being a free pass to Kscope13 or a Jawbone Jambox!

This is an opportunity for you to not only win some cool prizes but also to show just what is possible with APEX plugins (and don’t worry if you’re a beginner in APEX, there is a separate Experts category to make sure that everyone is judged as equally as possible).

APEX Quiz

APEX Quizzes Start on 18 June 2011

With the growing popularity and usage of Oracle Application Express, we are very excited to announce a new weekly Oracle APEX quiz launching on Saturday, 18th June. Weekly quizzes start on Saturday and end on Friday at midnight (UTC).

We have been deeply involved in the development (and success!) of the PL/SQL Challenge from the very beginning….and we have now taken the next logical step:

APEX Evangelists is now sponsoring a weekly APEX quiz, so you can now look forward to me and Dimitri Gielis of APEX Evangelists challenging you with some interesting quizzes. If you’re already a seasoned APEX developer or you are only just beginning your journey with APEX, then this is the perfect time to start competing in the APEX Quiz to help to deepen and broaden your knowledge about one of Oracle’s most exciting application development tools.

To play the APEX quiz starting 18 June, simply visit http://www.plsqlchallenge.com and choose the quiz in the Play a Quiz table. We also encourage you to submit your own ideas for APEX quizzes – and to volunteer as a reviewer (which you can do through the Feedback page).

We would like to see more developers playing the APEX quiz than the daily PL/SQL quiz (hey a little healthy competition is a good thing right?!). So help us spread the word! Let your friends co-workers know about the APEX quiz!

Expert Oracle Application Express

Expert Oracle Application Express

It’s been around 3 years since I wrote Pro Oracle Application Express (with a chapter contributed by Scott Spendolini), and like most first time authors I said “That was a great experience, but I’m in no hurry to write another book again!”.

Writing a technical book is a very rewarding experience, but trying to do it alongside your regular day job is tough (tougher than I ever imagined). Trying to meet publishers deadlines while still trying to  keep your (paying!) clients happy is very tough indeed.

However, a couple of events made me rethink my “never again” policy, firstly the very sad passing of Carl Backstrom and then the equally sad and unexpected passing of Scott Spadafore.

These two people helped me immensely during my time with Oracle Application Express and since I knew them both personally I wondered what I could do to help the families of two people who I admired immensely and also considered friends.

That’s when I came up with the idea of writing a collaborative book, with each chapter written by a different author who knew both Carl and Scott.

At ODTUG last year I approached people who I knew felt the same way about Carl and Scott as I did and I felt an enormous sense of pride that every single one of the authors didn’t hesitate in agreeing to contribute a chapter, so for that I am eternally grateful to:

There is some great technical content in this book, written by some of the worlds best known Oracle APEX experts. Even if you don’t think you need this book, buy it…PLEASE.

NOTE: ALL AUTHOR ROYALTIES ARE SPLIT 50/50 BETWEEN THE TWO MEMORIAL FUNDS.

A PLEA FROM ME: If you are only going to buy 1 book on APEX this year…please make it this one, if you are going to buy more than 1…well make sure one of them is this book!

APEX 4.0 released

APEX 4.0 just got released, this is the BIG one for APEX developers, we’ve been anxiously awaiting the release (and a few bets have been known to placed on when exactly it would be released!).

More information is available on Joels blog, and you can download APEX 4.0 as always from the main OTN APEX page here

PL/SQL Challenge – Goes Live!

The PL/SQL Challenge website has just PL/SQL Challenge - Home gone live!

If you haven’t heard about it yet, it’s a website where you can pit your wits against a daily question by none other than Steven Feuerstein (yes that Steven Feuerstein!) and Finn Ellebaek Nielsen. Wait it’s even cooler than that, you can win cash (and other!) prizes and if that’s not enough to tempt you then you can see how you rank against other PL/SQL developers all over the world (and who wouldn’t want to know that!).

Steven asked APEX Evangelists (what seems like a long time ago – before we formed Sumneva) to help him create the front-end for the PL/SQL Challenge website (we previously created the I Love PL/SQL site for him) and we (myself, Dimitri Gielis and Paul Broughton) have worked in our ‘spare time’ to help to bring the site to life.

We of course used Oracle Application Express to create the front-end application (all of the back-end is PL/SQL code, what else did you expect from Steven?!), and even though I’m biased I have to say this makes for a dream development environment.

I have to say it’s been a pleasure to work with two professionals such as Steven and Finn. It really has been a baptism by fire for Paul working on such a project (how many interns get the chance to work with such giants as Steven?) but he more than rose to meet the challenge, thanks Paul!

So what are you waiting for? Go along…sign up…play the quiz…and see how well you can do (someone is going to win those prizes!).

Application Express 4.0 – Early Adopter 2 Now Available

apex40

If you didn’t already see the news, the EA2 release of APEX4.0 has just been opened up.

Head over to www.tryapexnow.com, sign up for a workspace and try out all the cool new features.

EA2 includes the following key features -

  • Websheets (this will be huge!)
  • New collection enhancements
  • Tree region
  • Debugging has been rewritten

and many more (see Joel’s blog post for a full description).

APEX 4.0 is going to be a huge release and will have (arguably) the biggest impact of any APEX release, it’s certainly interesting times being involved in the APEX community.

Views and Order By

Developers like views…they can simplify things and hide (protect us from) underlying complexity.

For example, would you rather write the query -

SELECT
  ename,
  department_name
FROM
  emp_vw

or

SELECT
  e.ename,
  d.dname
FROM
  emp e,
  dept d
WHERE
  e.deptno = d.deptno;

It’s a rhetorical question so please don’t say “I prefer the second”…otherwise there’s no point me continuing this post. Anyway, that’s quite a simple example, imagine the view hides all sorts of complexity (analytics, subquerys etc).

The view gives us a single ‘point of truth’, we can tell developers “use that view, it contains all the information you need, you don’t need to understand all the logic yourself”, views are a very powerful tool for code re-usability (and simplification).

However, what if someone codes a view like this -

CREATE OR REPLACE VIEW empdept_vw AS
SELECT
  e.ename,
  d.dname,
  e.sal
FROM
  emp e,
  dept d
WHERE
  e.deptno = d.deptno
ORDER BY d.dname;

Notice the order by there? They probably/possibly created that view to use directly in a report, adding the ORDER BY into the view so they could just write -

SELECT * FROM empdept_vw

rather than

SELECT * FROM empdept_vw edv ORDER BY edv.dname

Well that’s fine, but what is someone else later on uses that view in this way -

SELECT * from empdept_vw edv ORDER BY edv.sal DESC

Well we’re now potentially making the database do more work because the query is sorting the data in a different way to the view sorts it (so therefore the sorting in the view is essentially redundant). The key point here is that the database cost based optimizer might be smart enough to figure out what you’re doing and eliminate the redundant sort, however there might be lots of cases where that doesn’t happen (consider the scenario where you have views built on top of views, with ORDER BY’s thrown in there at a deep level).

The cost-based optimizer gets smarter with every release of the Oracle datbase, however it will never (and I’m reasonably confident about this!) understand your data and requirements as much as you do (or rather as much as you should).

So, I would argue anytime you see a view with an ORDER BY in it you should really question why you’re doing that (rather than putting the ORDER BY in the query that uses the view). We can even make our job easier and look for any views that have an ORDER BY defined in them by querying DBA_VIEWS or USER_VIEWS. Unfortunately those views contain the text definition of the view in a LONG column rather than a CLOB, which means we can’t do a simple LIKE predicate -

JES@dbtest> select * from user_views where upper(text) like '%ORDER BY%';
                                     *
ERROR at line 1:
ORA-00932: inconsistent datatypes: expected NUMBER got LONG

We can get round this in a number of ways (such as creating a copy of the DBA_VIEWS or USER_VIEWS in a local table converting the LONG column to a CLOB etc), or we can use a different approach like this -

JES@dbtest> select
  *
from
  user_views
where
  dbms_xmlgen.getxml('select text from user_views where view_name = ''' || view_name || '''') like '%ORDER BY%'

(note unfortunately I can’t remember who to credit with the DBMS_XMLGEN trick above, I saw it a long time ago and it’s been lost in the mists of time).

and yes…before you ask…in the schema I ran that query in I did find a view that had an unnecessary ORDER BY in ;)

I’d be interested to hear your thoughts on if you find ORDER BY’s in views a problem/issue/area-of-concern, or if it’s just me?

Increasing the speed of APEX Collections

I’d love to say “I’m quite often asked…”, but to be honest hardly anyone seems to use Collections in APEX (a very under utilised feature in my opinion).

However, a question does come up from time to time, often along the lines of “I am using a collection but it is slow…”.

Typically, you might create a collection in the following way -

APEX_COLLECTION.CREATE_COLLECTION_FROM_QUERY(
  p_collection_name => 'COLL1',
  p_query           => 'select * from emp',
  p_generate_md5    => 'NO');

This would create a collection (called ‘COLL1′) and populate it with the results of the query (select * from emp).

So, let’s take a quick example. Firstly I want to use a sizable table

JES@dbtest> create table my_all_objects as select * from all_objects;

Table created.

JES@dbtest> select count(*) from my_all_objects;

  COUNT(*)
----------
     55853

So now I’m going to create an APEX application, which has the following code in a process:

APEX_COLLECTION.CREATE_COLLECTION_FROM_QUERY(
  p_collection_name => 'COLL1',
  p_query           => 'select * from my_all_objects',
  p_generate_md5    => 'NO');

It’s not really important to see the APEX application as such, what is important is to see how long it takes to run this process. There are lots of ways I can achieve that (putting in my own instrumentation etc), but APEX comes with a nice debug mode, which shows me timing information for everything that it does when you run a page. Running that page in debug mode I see something similar to -

0.03: ...Process "Create 1": PLSQL (AFTER_SUBMIT) APEX_COLLECTION.CREATE_COLLECTION_FROM_QUERY( p_collection_name => 'COLL1', p_query => 'SELECT * FROM my_all_objects', p_generate_md5 => 'NO');
18.57: ...Do not run process "Create_B", process point=AFTER_SUBMIT, condition type=, when button pressed=CREATE_B

The important bit here is the difference in timings (18.57 – 0.03) between the two lines, so that means my process took around 18.54 seconds to create the collection. 18 seconds is a long time for an user to wait for something to happen in a web application.

So, what can we do to improve things? Well if you look in the documentation for APEX_COLLECTION you’ll see there is another routine called CREATE_COLLECTION_FROM_QUERY_B. From the documentation -

The CREATE_COLLECTION_FROM_QUERY_B method offers significantly faster performance than the CREATE_COLLECTION_FROM_QUERY method by performing bulk SQL operations, but has the following limitations:

No column value in the select list of the query can be more than 2,000 bytes. If a row is encountered that has a column value of more than 2,000 bytes, an error will be raised during execution.

The MD5 checksum will not be computed for any members in the collection.

Ok, so if we can live with those limitations (the restriction about not computing the checksum is not as significant as it might at first seem, since we could also manually calculate it ourselves once the collection has been populated), then it’s worth trying it, so changing our code from -

APEX_COLLECTION.CREATE_COLLECTION_FROM_QUERY(
  p_collection_name => 'COLL1',
  p_query           => 'SELECT * FROM my_all_objects',
  p_generate_md5    => 'NO');

to

APEX_COLLECTION.CREATE_COLLECTION_FROM_QUERY_B(
  p_collection_name => 'COLL1',
  p_query           => 'SELECT * FROM my_all_objects');

as you can see, it’s a relatively minor change. So let’s run the page in debug mode again and see if there is an improvement:

0.03: ...Process "Create_B": PLSQL (AFTER_SUBMIT) APEX_COLLECTION.CREATE_COLLECTION_FROM_QUERY_B( p_collection_name => 'COLL1', p_query => 'SELECT * FROM my_all_objects');
5.25: Branch point: AFTER_PROCESSING

So this time it took around 5.2 seconds (5.25 – 0.03) to create the collection. (Note that I ran these tests multiple times to remove any caching issues).

Whilst I’d say 5.2 seconds is still a long time for a user to wait for a webpage, it’s a significant improvement over 18 seconds. Note your own results might vary with the difference in timings.

APEX Listener EA2 is out!

Just a quick note to say that the APEX Listener Early Adopter 2 is out.

Kris Rice blogged about the features and fixes available in this EA, I just quickly tested out the XLS upload (turns it into an APEX collection….very very cool!).

The APEX Listener is definitely introducing some interesting features (like the ability to record and replay sessions), so it will very soon outshine the Oracle HTTP Server in my opinion.