Just about anything

Yet another blog about programming, technology and general musings on life

Variable Precedence

Posted by calvinkrishy on May 25, 2007

Oracle ‘knows’ which token is a variable and which is a column in a table. This becomes important when you are using a variable whose name clashes with that of a column name in a predicate. Consider the following:

create table tbl (x number)
/
insert into tbl values(1)
/
declare
x number;
d number;
begin
select count(*) into d
from tbl where x > 0;
end;

This compiles fine under Oracle. Oracle ‘knows’ that the x referred to in the query is the column and not the variable. But a similar piece of code under Informix results in ‘-696 Variable () has undefined value’.

create table tbl(x int);
insert into tbl values(1);
create procedure demo_err()
define d, x int;
select count(*) into d
from tbl where x > 0;
end procedure;
call demo_err();

In fact, the Informix guide explicitly states that the local variable takes precedence.

Whose handling is more appropriate? Either way, I feel the IDS folks should throw up easily understandable error – ‘Variable () has undefined value’ spoilt a n00b’s afternoon :(

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>