Quick Draw Fail
It rarely pays to answer too quickly.
Yesterday’s question at the PL/SQL Challenge was about aliases for expressions in cursor-based record types.
DECLARE CURSOR profitable_internet_stocks IS SELECT SUM (share_price) FROM nasdaq_listings WHERE profits > 0 AND sector = 'INTERNET'; few_and_far_in_between profitable_internet_stocks%ROWTYPE; BEGIN OPEN profitable_internet_stocks; FETCH profitable_internet_stocks INTO few_and_far_in_between; CLOSE profitable_internet_stocks; /*[display_statement]*/ END;
The question asked what code, inserted where the “display_statement” comment is, would display the result of the query. Without thinking too hard about it, I ticked the fourth option as correct:
I had this stupid idea that Oracle would step in and magically create an alias for the column*. A millisecond after clicking “Accept”, I realised I’d got it wrong. I’d assumed that at least one of the answers were likely to be correct, which is obviously not true.
* EDIT: Gary Myers has blogged about this too and explains that Oracle does, indeed, create an alias.