Code Listing 6: Returning the next value of any sequence, using a generic function

 1  CREATE OR REPLACE FUNCTION next_pky (seq_in IN VARCHAR2)
 2     RETURN PLS_INTEGER AUTHID CURRENT_USER
 3  IS
 4     retval PLS_INTEGER;
 5  BEGIN
 6     EXECUTE IMMEDIATE 'SELECT ' || seq_in
 7                       || '.NEXTVAL FROM onerow'
 8                  INTO retval;
 9    
10     RETURN retval;
11 END next_pky;
12 /