Home » SQL & PL/SQL » SQL & PL/SQL » sequence in package
sequence in package [message #291712] Sun, 06 January 2008 03:51 Go to next message
ridhi_sundar
Messages: 184
Registered: November 2007
Location: Bangalore
Senior Member
Can sequence be created in a package?

If so how?
Re: sequence in package [message #291714 is a reply to message #291712] Sun, 06 January 2008 03:54 Go to previous messageGo to next message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Can this be done? Yes
Is this a good practice? No
How? Just search in this forum this has been asked many times.

Also, before you'll ask it in a short while, search for "ORA-01031" or "insufficient privileges", it is likely you will get it during your test.

Regards
Michel

[Updated on: Sun, 06 January 2008 03:56]

Report message to a moderator

Re: sequence in package [message #291776 is a reply to message #291714] Sun, 06 January 2008 14:14 Go to previous message
Frank Naude
Messages: 4502
Registered: April 1998
Senior Member
To add to Michel's post - here's a quick example:

SQL> CREATE OR REPLACE PACKAGE my_pkg AS
  2    PROCEDURE create_seq(seq VARCHAR2);
  3  END my_pkg;
  4  /

Package created.

SQL>
SQL> CREATE OR REPLACE PACKAGE BODY my_pkg AS
  2    PROCEDURE create_seq(seq VARCHAR2) IS
  3    BEGIN
  4      EXECUTE IMMEDIATE 'CREATE SEQUENCE '||seq;
  5    END create_seq;
  6  END my_pkg;
  7  /

Package body created.

SQL>
SQL> EXEC my_pkg.create_seq('x');

PL/SQL procedure successfully completed.

SQL>
SQL> SELECT * FROM user_sequences WHERE sequence_name = 'X';

SEQUENCE_NAME  MIN_VALUE  MAX_VALUE INCREMENT_BY C O CACHE_SIZE LAST_NUMBER
------------- ---------- ---------- ------------ - - ---------- -----------
X                      1 1.0000E+27            1 N N         20           1
Previous Topic: Excluding records in result set
Next Topic: help with outer join
Goto Forum:
  


Current Time: Sat Dec 03 13:57:17 CST 2016

Total time taken to generate the page: 0.08861 seconds