Mar 16, 2009
I discovered today that in Oracle 10g (and I presume in earlier versions also) it is not possible to directly assign a sequence value in to a PLSQL variable, hence neither of the 2 following examples will compile in 10g:
1:
PROCEDURE set_up_test_data(no_of_days NUMBER)
IS
-- Doesn't compile
nice_unique_number NUMBER := mysequence.nextval;
BEGIN
-- do stuff here...
END set_up_test_data;
2:
PROCEDURE set_up_test_data(no_of_days NUMBER)
IS
nice_unique_number NUMBER;
BEGIN
-- Doesn't compile.
nice_unique_number := mysequence.nextval;
-- do stuff here...
END set_up_test_data;
A bit of googling suggests that a common workaround to this is to be do a SELECT INTO using the dual table, as below:
PROCEDURE set_up_test_data(no_of_days NUMBER)
IS
nice_unique_number NUMBER;
BEGIN
--Works nicely
SELECT mysequence.nextval INTO nice_unique_number FROM dual;
-- do stuff here...
END set_up_test_data;
Note: This no appears to be an issue as of Oracle 11g (search for Straight Sequences).
EdD