Monday, January 12, 2015

PL/SQL: FOR r IN (SELECT ... INTO ) ... Hmm?

Today, I came across a funny piece in some sort of legacy code that I think should not compile:
for r in ( select i, t into rec.i, rec.t -- Hmm??? from tq84_foo ) loop .... end loop;

My understanding is that the INTO clause should not be valid because the select statement is embeded in a FOR r IN (SELECT...) loop. Yet, it compiles, at least in Oracle 11i.

Here's a little test script for demonstration purposes:

create table tq84_foo ( i number, t varchar2(10) ); insert into tq84_foo values (1, 'abc'); insert into tq84_foo values (2, 'def'); declare rec tq84_foo%rowtype; begin for r in ( select i, t into rec.i, rec.t -- Hmm??? from tq84_foo ) loop dbms_output.put_line('rec: i= ' || rec.i || ', t=' || rec.t); end loop; end; / drop table tq84_foo purge;

The output is

rec: i= , t= rec: i= , t=
My according question on stackoverflow

Tuesday, January 6, 2015

Little things that make live easier #7: set relativenumber in vim

Today, I stumbled upon an option in vim that I think will make my life easier: :set relativefilenumber

With this option enabled, vim will show how many lines a line is apart from the line with the cursor:

So, if I need to quickly jump to the select statement, I can type 9j (9 because I see that it is 9 lines down, and j because that moves the cursor down).