Se vuoi usare rownum e order by tu hai per inserire l'ordine in una sottoquery. Non c'è altro modo per garantire di ottenere il valore corretto.
È anche buona norma affrontare la possibilità che non ci sia un id che corrisponde alla tua richiesta. Ho aggiunto un ulteriore begin... end; bloccare per affrontare questo.
declare
v_id a.id%type;
begin
begin
select id into v_id
from ( select id
from a
where name = 'test'
order by id desc )
where rownum < 2
;
exception when no_data_found then
v_id := null;
end;
dbms_output.put_line(v_id);
doSomething(v_id);
end;
/
Come ha notato @raukh (mentre stavo scrivendo questo!) il problema è print , che dovrebbe essere dbms_output.put_line()