You never stop learning about Oracle features


Oracle‘s name is no coincidence. It is truly an oracle, telling you mystical, secret things about your database. It may take great expertise and skill to optimally extract that knowledge from this monster. While it implements vast parts of the SQL:2008 standard, it ships with a lot of features no other database has, but which are likely to make it into the SQL:2011 and subsequent standards, eventually.

One particular syntax clause is the PARTITION BY clause. It is very similar to the GROUP BY clause, but it can appear in various other contexts. The most trivial one is that of window functions / analytical functions. The most advanced one is that of the MODEL clause (which I shall blog about soon). But one of the most hidden ones is that of the OUTER JOIN clause. With Oracle, you can issue a “partitioned outer join”.

The formal definition of an Oracle OUTER JOIN clause can be seen here:

 

The query_partition_clause is a regular “PARTITION BY expr” clause. Now, this useful addition that can be put to the left or to the right of the actual OUTER JOIN clause, allowing to specify a means of how to partition either side in a way that there will be at least one (possibly empty) record for every partition, in case the OUTER JOIN does not produce any records for such a partition. Whew.

In more intelligible English: This clause helps filling your result set with blank records. There!

So, whenever you feel you need to fill in some blank rows with Oracle, remember that you might just have found yourself a use-case for the partitioned outer join! (This clause will be supported by jOOQ 2.5.0)

Tags: , , , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 1,613 other followers

%d bloggers like this: