Tag: sql

The first matching row

I was recently asked when presented with a query along the lines: SQL> select * from 2 ( select x 3 from t1 4 where x = :b1 5 union all 6 select x 7 from t2 8 where x = :b1 9 )…

Equi-sized partitions on random data

Had an interesting AskTom question today about dynamically keeping partition sizes in check. The poster had large table, already partitioned, but since there was no logical column to do a range partition on, it was partitioned on a surrogate primary key value. Due to…

Something new learned every day

One of the reasons I leapt at the chance to be on the AskTom team when we resurrected the site, was that it’s like free training.  You get questions on topics you have not visited before, and you get new angles on things you…

On building SQL

I had a fun question on AskTom over the weekend, that of, how to display a monthly calendar for any provided date using just SQL. You can see the question and the answer here But I thought it might be worth explaining the process. …

DEFAULT SEQ.NEXTVAL in 12c

One of the cool things in 12c is that (finally after all these years) a sequence can be assigned as the default value for a column. Of course, some may say “big deal” – after all, it is trivial to create a simple trigger…

Never rely on an assumed order

We’ve (hopefully) all had it drummed into us enough times – you cannot assume the order of results from queries unless you explicitly include an ORDER BY statement. Here’s another trivial example of this- I was doing a little demo script for an AskTom…

Bitwise operations

The long existing BITAND function is now within the documentation, to let you do logical AND on two numbers, and is also available from PL/SQL   If you need other bit operations, a little boolean math should suffice Just make sure you stay within…