473,403 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

SQL sequence creation

Hi there,

I'm trying to write a piece of sql to set an Oracle sequence's nextval
to a number specified my the max value in a set of columns. The
sequence is populating these columns, so I want to give it a kick if
something goes wrong so itwon't try to duplicate numbers.

I'm creating the sequence with

create sequence my seq
minvalue 1
maxvalue 999999999999999999999999999
start with X
increment by 1
cache 20;

and I'm getting the required vlaue by a

select max(Col1) from (select Col1 from TAB1
union
select Col2 from TAB2
union
..... etc. etc. etc.)

The question is how do I automatically get the single value in this
into the X in the sequence? I tried placing the code in for the X, but
got an ORA-01722 for it not being a proper number.

Ta in advance,
Steve.
Jul 19 '05 #1
1 29489

"Steve Morrell" <St***********@techprt.co.uk> wrote in message
news:3d**************************@posting.google.c om...
Hi there,

I'm trying to write a piece of sql to set an Oracle sequence's nextval
to a number specified my the max value in a set of columns. The
sequence is populating these columns, so I want to give it a kick if
something goes wrong so itwon't try to duplicate numbers.

I'm creating the sequence with

create sequence my seq
minvalue 1
maxvalue 999999999999999999999999999
start with X
increment by 1
cache 20;

and I'm getting the required vlaue by a

select max(Col1) from (select Col1 from TAB1
union
select Col2 from TAB2
union
.... etc. etc. etc.)

The question is how do I automatically get the single value in this
into the X in the sequence? I tried placing the code in for the X, but
got an ORA-01722 for it not being a proper number.

Ta in advance,
Steve.


I doin;t think you will get the answer into your X value. IF using SQL*Plus
try it this way.

SPOOL seq.sql

SELECT 'create sequence....' || max(col1) || ' increment by....'
from (select col1 from tabe1.......)
/

SPOOL OFF

start seq

so you have a select statement to produce your cerate sequence statement,
whic is written to a file and then run automatically.
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Nick Dreyer | last post by:
I was quite surprised to notice that Sub New() gets called twice, once at declaration time and once at creation time. I can't figure out why it would be called at declaration if there is no class...
1
by: Marek Lewczuk | last post by:
Hello, I would like to ask if my problem with sequence is a proper behavior or this is a bug (probably not)... I have a table: CREATE TABLE "testtable" ( "serialfield" SERIAL,...
17
by: glenn.robinson | last post by:
Hello, DB2 for iSeries - V5R2 I have a table with a non-unique index, column name SEDOL. I need to extract the 2nd row from each set of SEDOL rows in the table. If only one SEDOL row exists...
21
by: John Salerno | last post by:
If I want to make a list of four items, e.g. L = , and then figure out if a certain element precedes another element, what would be the best way to do that? Looking at the built-in list...
1
by: SammyBar | last post by:
Hi all, I'm having troubles with a Symbol 9000 device (Compact Framework v 1.1) when activating the barcode scanner from a window. The problem is related to the Activated event of the form which...
2
by: David | last post by:
I am fairly new to ASP.Net and am using VS2005 and .Net 2.0 for page creation. I am using VB as a language and have VB code between script tags at the top of my page. I also have a button on my...
1
davydany
by: davydany | last post by:
Hey guys...a n00b Here for this site. I'm making a sequence class for my C++ class. And The thing is in the array that I have, lets say i put in {13,17,38,18}, when i see the current values for the...
7
by: desktop | last post by:
In the C++ standard page 472 it says that you can construct a std::set in linear time if the constructor gets a sorted sequence of elements. But how is this possible when insert takes logarithmic...
1
by: Steve Morrell | last post by:
Hi there, I'm trying to write a piece of sql to set an Oracle sequence's nextval to a number specified my the max value in a set of columns. The sequence is populating these columns, so I want...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.