Skip to content

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

Critical

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
9
declare
   l_sequence_number employees.employee_id%type;
begin
   select employees_seq.nextval
     into l_sequence_number
     from dual;
   my_package.do_something(l_sequence_number);
end;
/

Example (good)

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