@SequenceGenerator generating wrong sequence numbers on an Oracle database
Hello,
I have a JPA entity with the following annotation:
@SequenceGenerator(name = "PERS_GEN", sequenceName = "PERS_SEQ", initialValue = 1, allocationSize = 1)
But the ids created by this sequence are not incrementing one by one;they increment 20 by 20. What is the cause of this?And how can it be sold?
Hello,
You will need to reference the database docs on what the database cache setting means or how it behaves, or post on the JDBC forums as I don't really know. My testing by calling SELECT seq.NEXTVAL FROM dual repeatedly caused it to return numbers sequentially based on the increment by value. I suspect this was because I was using the same session/connect etc and might be different if using different connections, timing etc. Have you tried creating the sequence with the nocache option? The cache 20 is not something that would be set by EclipseLink and is likely a database default, and I do not see why START WITH 21 would be used if the annotation specified initialValue = 1 - how are you checking the sequence that gets created? You can turn on EclipseLink logging to Finest to see the SQL it generates, but I would suggest you create the sequence object yourself - or have JPA create a DDL file and use it to create the tables. See http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)#Using_EclipseLink_JPA_Extensions_for_Schema_Generation for ddl generation options.
I found this http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:369390500346406705 discussion on database sequence cache sizes that might help.
Regards,
Chris
Similar Messages
-
How to generate random sequence numbers
Hello experts
Iu2019m writing a custom program and pulling data from VBAK & VBAP. As per requirement I also need to generate a sequence number randomly and finally store all data in text file and upload at server. The hiccup is I donu2019t know how to generate sequence numbers. Can somebody please show me how I can accomplish it?
Thanks a lot in advanceFind the below code,
data: lv_range type datatype-char0128.
call function 'RANDOM_C'
exporting
len_min = 20
len_max = 20
char_min = 1
char_max = 20
importing
rnd_value = lv_range.
LV_RANGE param will have a random value..
If you need number you can use the FM "RANDOM_I4"
Thanks,
Prathap -
Hi,
I am looking for an algorithm to generate alphanumeric sequence numbers in ABAP.
The sequence numbers should be in the following format
AAAA
AAAB
AAAC
AAAZ
AABA
AABB
AABC
AABZ
ZZZZ
Is there any built-in function module provided by SAP to accomplish this? Or something like a FOR statement as in C/C++?
Please help.
Helpful answers will be immediately rewarded.
Thank you.Hi,
I'm not sure, but maybe you can create a number range with SNRO for alphanumerical values
otherwise you have to create your own logic (you can use hexadecimal to ascii conversion in ABAP to increment the alphanumerical values)
Kind regards, Rob Dielemans -
Version : Oracle Apps 11.5.1 OS : HP-UX 64 bit.
Module : Order Management.
I want to generate unique sequence numbers for my shipment documents. For example, I have 2 customers A and B. I want my invoice numbers as A-001 for first customer, and A-002 for second customer and so on.
How to generate such a sequence (alphanumeric). Any suggestions?
TIA.Version : Oracle Apps 11.5.1 OS : HP-UX 64 bit.
Module : Order Management.
I want to generate unique sequence numbers for my shipment documents. For example, I have 2 customers A and B. I want my invoice numbers as A-001 for first customer, and A-002 for second customer and so on.
How to generate such a sequence (alphanumeric). Any suggestions?
TIA. -
Generate XML file from an Oracle Database Table
Hello All,
I want to generate a xml file from an Oracle Database table which contains a blob column.
Can somebody give pointers on this please.
Thanks in advance
SulakshanaUse the DBMS_XMLGEN package.
-
Generate XML Schema from Oracle Database
Is there a utility that would allow our team to generate XML Schemas directly from existing Oracle databases? Or do you have a suggestion on how to achieve this?
Thank you.Hey, The Schema Processor is available in the Technologies section on this site. Just download it and see the samples. You will get the way for doing it. If you are having problems then just call me.
Bye.
null -
Steps if Oracle Database Crashed
Hi All,
Can someone write me sequence of steps if Oracle database get crashed. Just steps and not the detail.
Thanks
PraveenFirst try 'recover database' command in sys login
If it fails,
1. See for the alert.log for exact error if any
2. if a control file is corrupted, create new control file
If there is hard-drive problem, bad sector etc then no chance ! Have to format or change hard drive and re-install oracle. -
Sequence numbers not generated sequentially?
Our situation: We have encountered an issue with our database, where it appears that a sequence has generated a number out of sequence, that is, to fill in a gap left previously. That is, in the affected table, we have records like:
Seq No Date (DD/MM/YY)
1 29/12/08
2 29/12/08
3 4/1/09
4 29/12/08
The code that actually updates the database is from a third party, so I am unable to prove the following, but the vendor assures me that:
1. The sequence numbers are generated using "select message_number.nextval from dual".
2. The Date column is not modified after the record is created. ( Nor is it supposed to be )
The sequence is created by "CREATE SEQUENCE MESSAGE_NUMBER START WITH 10000000 INCREMENT BY 1 MINVALUE 10000000 CACHE 20 NOCYCLE NOORDER"
This was detected only yesterday, after the event, and is very uncommon ( I have not found another instance, but there are over 7,000,000 records, so I haven't performed an exhaustive search). We are relying on the sequence numbers always being generated sequentially, as in each message_number.nextval is greater than the previous one.
I don't think that the date change was due to a user accidentaly changing the date. Related records to '3' are also dated 4/1/09, there is no facility for a user to change the date outside of accessing the database directly, and even the developers do not have write access to this database.
My questions:
1. Is this normal behaviour for a sequence? To go back and fill in a gap like this? If so we'll have to change one of the assumptions of one of our modules.
2. Should the sequence be defined with 'ORDER' rather than 'NOORDER' to stop this?
3. Could this be a bug in the sequence number generation? We are using Oracle 9.2.0.1.0.
4. Is this situation "impossible", and therefore there is a bug in the vendor library that we need to track down.
Thanks for your help,
Wayne.wayneb wrote:
Our situation: We have encountered an issue with our database, where it appears that a sequence has generated a number out of sequence, that is, to fill in a gap left previously. That is, in the affected table, we have records like:
Seq No Date (DD/MM/YY)
1 29/12/08
2 29/12/08
3 4/1/09
4 29/12/08
The code that actually updates the database is from a third party, so I am unable to prove the following, but the vendor assures me that:
1. The sequence numbers are generated using "select message_number.nextval from dual".
2. The Date column is not modified after the record is created. ( Nor is it supposed to be )There might be a delay between fetching the sequence and storing the sysdate? value in the database.
maybe some user prepared a new record. Then went to some new years eve party and when he came back at the begining of next year he commited the data (record send to database, database is adding date column by some trigger...).
>
The sequence is created by "CREATE SEQUENCE MESSAGE_NUMBER START WITH 10000000 INCREMENT BY 1 MINVALUE 10000000 CACHE 20 NOCYCLE NOORDER"
This was detected only yesterday, after the event, and is very uncommon ( I have not found another instance, but there are over 7,000,000 records, so I haven't performed an exhaustive search). We are relying on the sequence numbers always being generated sequentially, as in each message_number.nextval is greater than the previous one.
I don't think that the date change was due to a user accidentaly changing the date. Related records to '3' are also dated 4/1/09, there is no facility for a user to change the date outside of accessing the database directly, and even the developers do not have write access to this database.
My questions:
1. Is this normal behaviour for a sequence? To go back and fill in a gap like this? If so we'll have to change one of the assumptions of one of our modules.No sequences don't fill gaps. However it is possible to fetch and cache values from a sequence for later usage. Especially in a RAC environment you can get sequence values that are not in order of time.
2. Should the sequence be defined with 'ORDER' rather than 'NOORDER' to stop this?No.
3. Could this be a bug in the sequence number generation? We are using Oracle 9.2.0.1.0.Extremly unlikely, but you can always check Metalink.
4. Is this situation "impossible", and therefore there is a bug in the vendor library that we need to track down.You can create such situations programatically. Whether it is a bug depends on the specifications for the software.
>
Thanks for your help,
Wayne.Edited by: Sven W. on Mar 24, 2009 5:00 PM -
ALE Change pointer idocs generated in wrong sequence
We are using the serialization group to generate the MATMAS and CLFMAS idocs with the sequence MATMAS generated first and then CLFMAS.
Normally,this seems to work fine with the idocs generated in the right sequence.
However, during a period of every 24hours, I could see a couple of MATMAS and CLFMAS idocs being generated in the WRONG sequence with CLFMAS generated first and not MATMAS as maintained in the serialization group.
What could be the reason?
I checked in the BDCP and BDCPV tables, the timestamps for the wrong sequence idocs seem to be correct with MATMAS before CLFMAS. However the actual idoc creation time is not in correct sequence.Hi,
Can you check your serialization group via tcode BD44 and check the sequence number for MATMAS and CLFMAS?
Hope this will help.
Regards,
Ferry Lianto -
Generate alphanumeric sequence using oracle sequence
Hi,
Can we generate alphanumeric sequence from Oracle sequence.
Sequence would be something like this. Please advice
TEMP-0001
TEMP-0002
TEMP-0010
Thanks,
Lakhi,
You can try below procedure...
SQL> create sequence sec
2 minvalue 0
3 start with 001
4 increment by 1
5 nocache;
Sequence created.
SQL> select 'temp-'||to_char(sec.nextval) from dual;
'TEMP-'||TO_CHAR(SEC.NEXTVAL)
temp-1 -
How to control the connection numbers in Oracle database
Post Author: admincrystal_2008
CA Forum: Data Connectivity and SQL
Hello,
We use Crystal Report XI R2 and Oracle 10.2 database. This is a web based application on Windows server 2003. After generating the report user usually kill the broswer, but the connection is still in Oracle database. Is teher a way to set up the max connection numbers on application web server?
Thanks for your input!Alekh wrote:
lists of jobs execute concurrently.Thats a definition we all aware of ;), I meant do you want to execute the jobs in a sequence? is there any dependency? is it more like scheduling?
And What kind of jobs you are talking about? running PL/SQL programs? or stats collection? or DB backup?
Regards,
Prazy -
Need SQL statement to generate a sequence number in the output rows
Hi folks. I need to create an SQL statement that generates a sequence number column in the output rows (records) such that the first returned row has this column set to 1, second returned row has the column set to 2, etc.
For example, consider the query:
SELECT income from employees WHERE income != 20000 ORDER BY income;
If employees.income contains 60,000, 20,000, 35,000, and 19,000 for respective rows, the output would be this:
19,000
35,000
60,000
I would like the SQL to also return a sequence number that is computed across the returned rows, resulting in two output columns:
1 19,000
2 35,000
3 60,000
Is there a simple SQL function that generates the sequence number, in order, and only for the returned rows? Or is there another way?
I'm stumped. Any help is appreciated! Thanks!
- Jack CochraneHi,
Welcome to the forum!
Use ROWNUM, like (example):
Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
Connected as hr
SQL> select rownum, first_name from (select e.first_name from employees e where e.first_name like 'J%' order by e.first_name);
ROWNUM FIRST_NAME
1 Jack
2 James
3 James
4 Janette
5 Jason
6 Jean
7 Jennifer
8 Jennifer
9 John
10 John
11 John
12 Jonathon
13 Jose Manuel
14 Joshua
15 Julia
16 Julia
16 rows selected
SQL> But rememeber if you want to be sure of unique numbers in certain field is better to use sequences and use seq_name.nextval each time you need.
Regards, -
Sequence numbers - with no gaps!
I seek some advice from anyone with first hand experience in this area.
My need is simple; generate a new ID number for every order for use as the primary key.
Obviously this simple exercise could be a bottleneck as volumes ramp up, so I was pleased to find the Oracle feature to generate such numbers (efficiently presumably). However, upon closer reading it was apparent that aborted transactions would result in the loss of the number allocated to to that order if another transaction had obtained the next sequence number already (as one would want it to, rather than serializing transactions).
I don't want to have gaps in the sequence as the system needs a high degree of auditability. I am thinking of utilising the Autonomous Transaction feature to write the newly acquired sequence number to the order file with a flag indicating that the record is incomplete, and that record is to be skipped by normal system applications (but available to audit reports which will interpret the reason correctly), then returning to the far more extensive main transaction which updates many tables.
The other alternative is to control sequence numbers within the application itself, or try to get the sequence number as the very last step before writing the new order record, but this probably won't guarantee gapless reliability either. The ID itself has no significance, and it doesn't matter if an ID was used out of strict date/time sequence, so I really don't want to execute these updates serially.
So, my question is this:
a) do most people use the builtin sequence number feature?
b) if so, is there a standard technique for avoiding or accounting for gaps?
c) if the application must take over this task, should the counter for the last used ID be in a single row table to minimise bottlenecks caused by the thisrecord being locked? There will be several such counters for different aspects of the application, and i thought of having each in its own row in a small table, but I'm concerned about the whole table getting locked and freezing out otherwise-unrelated updates.
Thanks for any advice you may have.
CSuser8821725 wrote:
I seek some advice from anyone with first hand experience in this area.
My need is simple; generate a new ID number for every order for use as the primary key.
Obviously this simple exercise could be a bottleneck as volumes ramp up, so I was pleased to find the Oracle feature to generate such numbers (efficiently presumably). However, upon closer reading it was apparent that aborted transactions would result in the loss of the number allocated to to that order if another transaction had obtained the next sequence number already (as one would want it to, rather than serializing transactions).
I don't want to have gaps in the sequence as the system needs a high degree of auditability. One of the very very few reasons for me to have a requirement for "gapless" sequences is if you have a kind of checking mechanism outside of the database that is implemented using this gapless number. I had such a requirement once, when exchanging files with another bank where we had to ensure that each file was transferred correctly and in the right order. Your "high degree of auditability" might be a similiar requirement. Just remember as long as you are still inside the database you can use other mechanisms to increase auditability.
I am thinking of utilising the Autonomous Transaction feature to write the newly acquired sequence number to the order file with a flag indicating that the record is incomplete, and that record is to be skipped by normal system applications (but available to audit reports which will interpret the reason correctly), then returning to the far more extensive main transaction which updates many tables.Hm. I don't see why you want to use Autonomous Transactions for this. It might be useful to lessen locking conflicts , depending how your future sequence mechanism will be built.
>
The other alternative is to control sequence numbers within the application itself, or try to get the sequence number as the very last step before writing the new order record, but this probably won't guarantee gapless reliability either. The ID itself has no significance, and it doesn't matter if an ID was used out of strict date/time sequence, so I really don't want to execute these updates serially.I would go for generating the sequence as the very last step. It needs to be set to NOCACHE of cause. This will garantee that the sequence fetched from mySeq.nextval is gapless. The problem is then in your application. Your application must be built in a way that it ensures to use this sequence, or at least to create a noticable alert when this generated sequence can't be used anymore. In essence this means. Each unhandled (database) error that happens after you fetched the next sequence value must be raised in a way that informs all relevant people about this error.
Example: It might be that you use the sequence to write an order file. What happens if halfway through writing the file your disk runs out of space? This can be such an issue where a sequenced value will be lost. Your organisation must take care of those things.
>
So, my question is this:
a) do most people use the builtin sequence number feature?Yes. But for some tasks a sequence is not the best way, for example if you want a numbering for each item of your order. This "sequence" needs to restart with every new order.
b) if so, is there a standard technique for avoiding or accounting for gaps?NOCACHE => Avoids gaps during generation
Database Trigger => Tries to use the sequence as late as possible
c) if the application must take over this task, should the counter for the last used ID be in a single row table to minimise bottlenecks caused by the thisrecord being locked? There will be several such counters for different aspects of the application, and i thought of having each in its own row in a small table, but I'm concerned about the whole table getting locked and freezing out otherwise-unrelated updates.This is a possibility and the issues you describe are why we avoid such a solution in general. Autonomous transactions help to reduce the locking conflict, but they increase the chance that you produce gaps.
>
Thanks for any advice you may have.
CSOracle can guarantee to produce gapless sequences. But it can't guarantee that your application uses such a sequence in a gapless way. -
Hi all,
I was wondering if you can help me here.
I am new to Oracle (having come from a SQL Server background) and I need to generate sequence numbers using a function.
This is the scenario
we have a table called APPS_CODES with columns CODE, VALUE
The values in this table are
213, Y
214, Y
215,N
We also have another table called SETCODES columns (ID, DESC)
values in this table are
2,AIR
3,BUS
4, TRAIN
Finally we have a sequence as follows
min value 1, maxvalue 9999999 cycle
Now what we require is a function that produces an id in the form
21320000001 to 21329999999.
this is how it needs to be generated:
It needs to select the min(CODE) from the APPS_CODE table where value=Y then concatenate this with the ID from set codes table where DESC=AIR then concatenate this with the sequence. The sequence should be left padded with 0s so as to start from 0000001.
Once the sequence reaches 9999999 then the APPS_CODE table needs to be updated and the current code should now have its value set to N so we can start using the next CODE where value=Y.
So when we reach 21329999999 the next value returned by the fucntion will be 21420000001 uptil 21229999999
Any help will be appreciated
thanks alotI have created the function which seems to work fine.
However when it gets to the 3 record it fails with the following error message
GEN3
2674040000001
Elapsed: 00:00:00.00
15:59:15 test@CAMDEVF8> /
GEN3
2674040000002
Elapsed: 00:00:00.00
16:03:45 test@CAMDEVF8> /
select gen3 from dual
ERROR at line 1:
ORA-00904: "N3_V": invalid identifier
ORA-06512: at "TUNDE.GEN3", line 15
Any help.
Fucntion is below
Thanks
Create or replace
Function gen3
RETURN VARCHAR2 IS
l_v VARCHAR2(30);
n_v INTEGER;
n2_v VARCHAR2(30);
n3_v NUMBER;
BEGIN
SELECT gen2.NEXTVAL INTO n_v
FROM dual;
SELECT value INTO n2_v FROM config_settings
WHERE KEY='Airline Code';
SELECT MIN(form_code) INTO n3_v FROM form_codes WHERE doc_type='EMCO' AND available='Y';
l_v:=n2_v||n3_v||lpad(n_v,7,'0');
IF n_v=3
THEN
EXECUTE IMMEDIATE 'UPDATE form_codes SET available=''N'' WHERE form_code = n3_v;
commit;
END IF;
RETURN l_v;
END gen3;
--grant execute on generate_document_number to cam_cust_role; -
Hi,
We have a requirement of generating sequence numbers for a table and we need to recycle them if some of them is deleted.
For example the following tabe Employee(Id,name)
ID NAME
1 XXX
2 YYY
3 ZZZ
4 AAA
The ID filed should have the next sequence number generated. When I call getnextID now, it should return 5
ID NAME
1 XXX
2 YYY
3 ZZZ
4 AAA
5 BBB
Now Let us assume I delete 3. The contents of the table aare
ID NAME
1 XXX
2 YYY
4 AAA
5 BBB
Now when getNextID, 3 should be returned.
How to achieve this in a best performing way in Oracle? Are there any patterns around it? Please note this should run in a multi user environment.
Thanks,
RamaI think the answers were based on the fact that you call it incorrectly sequence.
Your ConnectivityID is more as a resource that could be recycled. I see some similarities to the GSM telecom market where a resource(i.e. a phone number or a SIM card no) can be recycled when is not active anymore (under certain conditions however).
Personally I would generate a table of resources having the resource number (ConnectivityID) and resource status.
To simplify it, suppose that you have column status with 2 possible values, 0=available, 1=not available.
When you want to allocate the resource number(ConnectivityId) you will set the status to 1.
When the record is deleted then status will be updated back to 0.
Recycling a ConnectivityID will mean searching in the table for the lowest number having status=0.
Of course you don't expect this to be as fast as a sequence but I think this is a different requirement, IMO.
Regards
Al
Maybe you are looking for
-
Spool list output truncated after 255 char
Hi, I'm using ALV list(FM: Reuse_alv_list_display) in my report. When it is run in background, the output is sent to spool. The problem is the list is truncated after 255 characters. Is there any way to display more than 255 characters in spool? S
-
How to hide messagetextinput item on root node in HGRID
Hi, I have added one messagetextinput item in HGRID. But it is showing 3 items(one for root node, 2 for the actual items) when there are 2 rows in master node. +Employee |________| -101 |________| -102 |________| I want to hide the item at r
-
Hello out there. I have CS5 and have until recently been able to open Tiffs directly from Bridge into Camera Raw. I just installed I believe the latest patch 6.7.1. All the preferences are correct. Please note I have no problem opening Jpegs from Bri
-
Problem mit Webseite die aus Fireworks erstellt wurden sind!
Hallo Leute, ich hatte bis vor ein Jahr noch mit der Master Collegen CS 3 gearbeitet und Webseiten mit Hilfe von Fireworks erstellt. Jetzt bin ich umgestiegen auf Adobde CC und dann gab es die ersten Probleme Problem: Wenn ich eine Seite erstellt hab
-
Motion 5 - Keeps crashing when i use the text tool
Just installed the Motion 5. Crashes wheni use the text tool for no reason. the project browser doesn't load too. What happened to apple products? They used to be good.