473,396 Members | 1,779 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,396 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 29488

"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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.