実際のコードは、こんな感じに、採番した値をダイレクトに変数に代入できるようになった。
なんか、なんの違和感もない直感的なコードになってる気がする。
1 declare 2 num pls_integer; 3 begin 4 num := test_seq.nextval; 5 dbms_output.put_line(num); 6* end; SQL> SQL> / 2 PL/SQL procedure successfully completed.
ちなみに、これがOracle10gまでのコード。
やっぱり、select文って必要ないよな。
1 declare 2 num pls_integer; 3 begin 4 select test_seq.nextval into num from dual; 5 dbms_output.put_line(num); 6* end; SQL> SQL> / 3 PL/SQL procedure successfully completed.
Oracle10gで、11gの新機能を使ってみようとすると当然エラーとなる。
1 declare
2 num pls_integer;
3 begin
4 num := test_seq.nextval;
5 dbms_output.put_line(num);
6* end;
SQL> /
num := test_seq.nextval;
*
ERROR at line 4:
ORA-06550: line 4, column 19:
PLS-00357: Table,View Or Sequence reference 'TEST_SEQ.NEXTVAL' not allowed in
this context
ORA-06550: line 4, column 3:
PL/SQL: Statement ignored