The problem in this case is not related to the fact that v.ra
is NULL
, it's just a syntax error.
Most likely the error message you received is as follows:
ORA-06550: line 3, column 1: PLS-00221: 'RA' is not a procedure or is
ORA-06550: line 3, column 1: PL / SQL: Statement ignored
Often the error messages are not very clear on the reason for the error, but in this case the reason seems to be clear: v.ra;
is not a procedure or block of code that can be executed.
I did not quite understand its purpose with this statement, but the variable v
has a type that depends on the structure of the teste
table, so v.ra
should probably be NUMBER, CHAR, BLOB, DATE, or other type commonly used to define a column of a table. It will therefore not be possible to "execute" the expression v.ra;
When you changed the statement to v.ra := 0
passed or compiler a statement that it understands. In this case, this is an assignment. Hence your code has run without error.
To show that the problem did not even have to do with NULL, see the following anonymous block, without the assignment, running at SQL Fiddle.
declare v teste%rowtype;
begin
select ra into v.ra from teste where nome = 'Danilo';
dbms_output.put_line(v.ra);
end
;
/