Skip to content

G-7810: Never use SQL inside PL/SQL to read sequence numbers (or SYSDATE).

Major

Efficiency, Maintainability

Reason

Since Oracle Database 11g it is no longer needed to use a select statement to read a sequence (which would imply a context switch).

Example (bad)

1
2
3
4
5
6
7
8
declare
   l_sequence_number employees.employee_id%type;
begin
   select employees_seq.nextval
     into l_sequence_number
     from dual;
end;
/

Example (good)

1
2
3
4
5
6
declare
   l_sequence_number employees.employee_id%type;
begin
   l_sequence_number := employees_seq.nextval;
end;
/