Home » SQL & PL/SQL » SQL & PL/SQL » Sequence Start with Value
Sequence Start with Value [message #427413] Thu, 22 October 2009 08:33 Go to next message
ramr_Sw
Messages: 31
Registered: October 2009
Member
I have a sequence called id_sq

script for this is,

CREATE SEQUENCE id_seq
MINVALUE 1
MAXVALUE 999999999999999999999999999
START WITH 1000
INCREMENT BY 1
CACHE 20;

Instead of Start with 1000,I have to take this value from an column called SeqID(Data type : number) from Table 1.

Can you pls let me know whether it can be applied here?

thanks

Re: Sequence Start with Value [message #427415 is a reply to message #427413] Thu, 22 October 2009 08:52 Go to previous messageGo to next message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Either use a SQL*Plus variable and record the value of sequence in it or use PL/SQL and dynamic SQL to build the statement.

Please read OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code, use code tags and align the columns in result.
Use the "Preview Message" button to verify.
Also always post your Oracle version with 4 decimals.

Regards
Michel
Re: Sequence Start with Value [message #427418 is a reply to message #427415] Thu, 22 October 2009 09:01 Go to previous messageGo to next message
ramr_Sw
Messages: 31
Registered: October 2009
Member

Thanks for your reply.I ll read and implement in subsequent posts.
Re: Sequence Start with Value [message #427420 is a reply to message #427415] Thu, 22 October 2009 09:09 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
Or you could create the sequence with a Start of 1, and just select from it in SQL enough times to get the next value up to the required level.
Re: Sequence Start with Value [message #427526 is a reply to message #427420] Fri, 23 October 2009 01:51 Go to previous message
_jum
Messages: 508
Registered: February 2008
Senior Member
Or similar to @JRowbottom:
DROP SEQUENCE test_id_seq;

CREATE SEQUENCE test_id_seq MINVALUE 1 MAXVALUE 999999999999999999999999999 START WITH 1 INCREMENT BY 1;
Sequence created.

SELECT test_id_seq.NEXTVAL FROM DUAL;
   NEXTVAL
----------
         1

ALTER SEQUENCE test_id_seq INCREMENT BY 999;
Sequence altered.

SELECT test_id_seq.NEXTVAL FROM DUAL;
   NEXTVAL
----------
      1000

ALTER SEQUENCE test_id_seq INCREMENT BY 1;
Sequence altered.

SELECT test_id_seq.NEXTVAL FROM DUAL;
   NEXTVAL
----------
      1001
Previous Topic: Reading CSV file Using UTL_FILE
Next Topic: selecting rows where each value appears exactly once
Goto Forum:
  


Current Time: Sun Dec 04 08:26:06 CST 2016

Total time taken to generate the page: 0.27134 seconds