Resetting sequences....
Hi all,
I have this table which uses sequence as pk and somehow it went out-of-sync....i try to reset it using something like...
alter sequence <seq_name>
increment by 1
minvalue <maxvalue_at_present>
my question is
--how a sequence went out-of-sync all of a sudden when it has the maxvalue set to 999999999999999999999999999 ???
-- can i reset the sequence back to some mid-number....example
say if the seq was 9000 and it got reset by next 9000 (my mistake). Now the nextval from dual is 18000. since 9000 was incremented by another 9000 which are not used, can we reset it back to 9000 and then increment it by 1 again???
Any help is highly appreciated...thanks in advance....
Totally agree with everyone that there really shouldn't be a need to reset sequences, but I do know when doing testing there can be circumstances when you want the sequence to start at a particular value in order to bring disperate things back into sync... so in answer to...
can i reset the sequence back to some mid-numberYes you can...
e.g. I want to reset my sequence to 50...
SQL> select test.nextval from dual;
NEXTVAL
125
SQL> var v_inc number;
SQL> var v_resetno number;
SQL> exec :v_resetno := 50;
PL/SQL procedure successfully completed.
SQL> exec execute immediate 'select -(test.nextval-:x)-1 from dual' into :v_inc using :v_resetno;
PL/SQL procedure successfully completed.
SQL> exec execute immediate 'alter sequence test increment by '||:v_inc;
PL/SQL procedure successfully completed.
SQL> select test.nextval from dual;
NEXTVAL
49
SQL> alter sequence test increment by 1;
Sequence altered.
-- JOB DONE. The sequence is now ready to use... and will start at 50...
SQL> select test.nextval from dual;
NEXTVAL
50
SQL> select test.nextval from dual;
NEXTVAL
51
SQL>
Similar Messages
-
Behavioral Verilog OpenSparc T1 Reset sequence
Hi all,
I am trying to put together the simplest T1 system - single core single thread - to run some basic programs on it. In particular I would like to execute a sequence of instruction in the machine bypassing the cache.
I am having quite an hard time understanding how to reset properly the OpenSparc. There are several reset signals between asynchronous reset, synchronous and so on. I do believe that I turned off the efuse and bist procedure - enabling the FPGA flags - but I still do not see that the reset address is requested to the icache or itlb and so on.
I tried to lookup in the documentation for the reset sequence for the Opensparc but I could not find any information there. Is there anywhere else I can look?
Thanks
-AndreaAlso look at the design/sys/iop/rtl/iop_fpga.v that consolidates all resets going in to the SPARC core into one. SRISC stuff should be similar.
-
Getting error while reset sequence value
i hve created two table. and a sequence for other table. i want to do that when i insert into a first table, entries of other table should be deleted and sequence value should reset to 1. For that i have executed the following sql code
but getting the error:
create or replace Trigger m_sale_ainsert_trig
after insert on m_sale_bill
for each row
begin
DELETE FROM M_TEMP;
<<COLUMN_SEQUENCES>>
BEGIN
Alter Sequence M_TEMP_SEQ Restart with 1;
END COLUMN_SEQUENCES;
end;
Alter Trigger m_sale_ainsert_trig enable;
Warning: execution completed with warning
Trigger m_sale_ainsert_trig Compiled.
Alter Trigger m_sale_ainsert_trig succeeded.
5/4 PLS-00103: Encountered the symbol "ALTER" when expecting one of the following:
( begin case declare exit for goto if loop mod null pragma
raise return select update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
continue close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe purge
pls rectify it!!!!! what are the mistakes in this code?
Edited by: JKMourya on Mar 21, 2013 10:55 AMJKMourya wrote:
i hve created two table. and a sequence for other table. i want to do that when i insert into a first table, entries of other table should be deleted and sequence value should reset to 1. For that i have executed the following sql code
but getting the error:
create or replace Trigger m_sale_ainsert_trig
after insert on m_sale_bill
for each row
begin
DELETE FROM M_TEMP;
<<COLUMN_SEQUENCES>>
BEGIN
Alter Sequence M_TEMP_SEQ Restart with 1;
END COLUMN_SEQUENCES;
end;
Alter Trigger m_sale_ainsert_trig enable;
Warning: execution completed with warning
Trigger m_sale_ainsert_trig Compiled.
Alter Trigger m_sale_ainsert_trig succeeded.
5/4 PLS-00103: Encountered the symbol "ALTER" when expecting one of the following:
( begin case declare exit for goto if loop mod null pragma
raise return select update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
continue close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe purge
pls rectify it!!!!! what are the mistakes in this code?
Edited by: JKMourya on Mar 21, 2013 10:55 AMDDL inside PL/SQL is NOT allowed
you must (ab)use EXECUTE IMMEDIATE -
Finding ranges in a resetting sequence number column
Hi,
I'm trying to run a query to get daily transactions on an ATM machine
The record on the ATM Machine is as such
TRANSACTION DETAILS TRANSACTION DATE TRANSACTION_SEQUENCE
..............xyz............... MON-DD-YYYY 1 to 9999
now after each 9999 transactions the number sequence resets and from there on it is 1, 2, 3, 4 and so on.
Now I'm going to accept the ranges as:
From Date, From SEQ No
To Date, To Seq No
Then I'm searching as
DATE Between FR_DT and TO_DT
and (
(DATE = FR_DT >= FR_SEQ) and
(DATE = TO_DT <= TO_SEQ)
Problem emerges when the SEQ number resets. For Example I may have the TO_SEQ given as 1, but the previous sequence is 9999.
Let me know if I can explain something else as well.
I need your helpMaybe this could help you
where ( FR_SEQ < TO_SEQ
AND TRANSACTION_SEQUENCE between FR_SEQ and TO_SEQ
or ( FR_SEQ > TO_SEQ
AND (
TRANSACTION_SEQUENCE between FR_SEQ and 9999
OR TRANSACTION_SEQUENCE between 0 and TO_SEQ
)The first part will check when the TRANSACTION_SEQUENCE is falling between FR_SEQ and TO_SEQ
The second part will check when TO_SEQ have spanned over 9999
Alon -
Reset sequence after data import
Hi all,
I've got a problem where we import data into a table with an auto-incremented field for a primary key. After the data import, I can drop the sequence, check the max(primary key), and re-create it to start at the max value + 1. My problem is that I need to do this for a large number of tables and don't know how to write a script to do it. In the Create Sequence command, whenever I try to use a variable in the "START WITH" clause, I get an error.
Thanks in advance,
RaymondSpool sequence creation scipt result in a file and then run it.
Or use dynamic sql.
Or You can "drive" sequence forward issuing select myseq.nextval from dual; apropriate times. If You need "drive" sequence backwards alter it with increment -1, issue select myseq.nextval from dual; apropriate times and alter it with previous increment. -
Auto reset sequence or ID column for a view
Hi,
I just wanted to know what would be the best approach for creating an id column for a view. I tried the rownum but that doesnt cut it when I have to link it to other tables.user809921 wrote:
I got 3 tables
1. Inc
2. Def
3. Class
Well I want to take a column Type from each, which have different data and obtain all the permutations of it. Then set up a unique key, number.And do what with it? Store it in a new table? Does this need to be immutable and referenced in other tables (through a foreign key constraint for example)?
Hope I have explained my self better.A little better, but there's still a good deal of pertinent information missing. Take some time and describe in detail the BUSINESS problem you are facing, not the technical implementation you are attempting. At least, if you want a comprehensively applicable answer. -
Hi,
I need a clean solution for a daily sequence number (starts from 1 everyday). Clean in the sense that upon initial setup, I do not have to do anything and I can get my number everyday by just one jdbc call/query.
Thank you in advance.What is the business justification for this requirement? Normally, you should just use a regular non-resetting sequence. If users want to see a "pretty" sequence number, simply generate something for them when you query the data using the row_number, rank, or dense_rank analytic functions. If users want to see sequences reset, they probably also want to see gap-free sequences, which is not something that you can ever guarantee in a scalable system where multiple users are allowed, though you can present gap-free sequences of values at query time.
You can have a job that either drops and recreates the sequence every day or that goes through some logic to reset the sequence to 1 by changing the increment. This gets rather hairy, though, because the job will fail (or fail to run) on occasion and requires that no one be processing data at the time.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC -
Problems with a new IP phone 7906 after factory reset
Hi Guys
I am currently having problems with my new IP phone 7906 after doing factory reset and here is a video of it:
http://www.youtube.com/watch?v=vvCLtwIAwVw
I used this command I found on the net:
Hold down
while plugging in the phone and keep holding it until the message waiting indicator (red light) starts blinking. Then
release # and type 123456789*0# in sequence.
I was trying to switch my phone to sip and it also dont want to take tftp setup either.Tim,
Found this on the net
http://www.cisco.com/en/US/ts/fn/620/fn62949.html
Might be woth giving it a go
6.Pull power on the phone (even if power is PoE).
7.Hold down the # key on the phone.
8.Continue holding down the # key and re-apply power.
9.While still holding the # key wait for the Message Waiting Indicator (MWI) light on the handset to start flashing.
10.Once the MWI light is flashing, release the # key and enter the following sequence exactly on the keypad:
3491672850*#
Once this sequence has been entered on the IP Phone, if all the network criteria above have been met, it should begin its recovery process. This process can take up to 15 minutes to finish. The phone may appear to be doing nothing during this time. However, if the phone does not recover after 20 minutes then it is possible that the recovery is stuck. In this case, re-examine your network and verify that steps 1-4 are in place, then re-issue the factory reset sequence.
* Note: The factory reset sequence is a way for a phone to clear flash and still upload to a valid firmware image. This is facilitated by the termxx.default.loads file, but requires that the image files listed in the termxx.default.loads file are available in TFTP for the phone to download. Open the termxx.default.loads file in any text editor. This loads file is essentially just a packing list showing all the OS and application files the phone needs to function. The files include a cnu, cvm, dsp, app and jar files. Please make sure that these files as listed in the termxx.default.loads file are in TFTP. ("xx" will be either "06" for the CP-7906G model, or "11" for the CP-7911G model.)
Additional Diagnostic Steps:
- Try a hard-coded IP address as a test to see if this resolves the upgrade failures. If it does, and the number of failing IP Phones is relatively few, this procedure may be the most expedient. After the IP Phone upgrades successfully, reconfigure the IP Phone to use DHCP.
- Try putting the phone on a hub or a different switch and see if this helps change the startup timing enough so that the upgrade completes successfully.
Regards
Alex -
Repeated shutting-down after PMU reset
Hello-
Very suddenly I am having problems with my 8/2005 g4 iBook. It has started shutting down while in the sleep mode, so I came here to troubleshoot and found instructions to reset the PMU. I did so, but it continues to shut down. Any suggestions before I bring it to an Apple Care site? I also notice that the power cord shows a green light even if I remove the battery during this time (I tried removing the battery & turning on before I tried resetting the PMU). Otherwise, the computer seems to be fine, albeit a little slower than it was a year ago.
Thank you much!That's an odd set of symptoms; and I wonder if the cause was something
else before the PMU reset sequence. You did the PMU with computer off,
as per AppleSupport document #14449 instructions - and it shuts down.
Not sure if something like the PRAM/NVRAM (one or both) could be
corrupted. The resets for these require different procedures. A variety
of things could be the cause of a sudden shutdown, to include some
hardware items in addition to the non-volitile ram, and parameter random
access memory. A sudden shutdown in some different models involved
other factors not reported alot in the iBookG4. The Intel® MacBook uses
a different technology so its sudden shutdown on a few models was CPU
heat buildup in some known examples; when proven to not be lesser causes.
Sudden shutdown symptoms can mimic more common causes of system
failure (bad RAM, improperly seated RAM, improperly seated hard drive,
bad software install, bad battery, bad AC adapter, corrupted PRAM,
corrupted NVRAM) which ALL must be ruled out. Since you have Apple
Care, any hardware component failures would be covered. Did you try
running the Apple Hardware Test from the boot/install DVD? It may not
catch this kind of problem, but you could tell the technician you ran it.
I have not run mine, but hear you boot from the install disc #1 and hold
the Opt key down and then after awhile you'd get a choice of startup items.
Did you upgrade the RAM lately? Some poorer RAM may cause issues;
but usually kernel panic activity is seen with bad RAM in the user slot.
If the strange behavor occurred after a step update from 10.4.7 to 4.8,
some users would try the Combo large update file installed over it all;
being sure to repair disk permissions before & after all software updates.
But the symptoms don't necessarily point that way.
You should try to archive your personal stuff on to some media outside
of the computer's hard drive; in case some tech has to wipe the drive or
do something else to the machine while it is away for repairs. If you have
an external FireWire enclosed drive, you may try making a clone of it all.
One level of troubleshooting may include using Disk Utility's tools on the
boot installer disc and totally wiping/zeroing data/reformatting the HDD.
This is where a bootable clone of your whole hard drive would be handy;
to make a full restoration back to the computer's drive afterward.
Hopefully someone with less drastic (and less wordy) ideas will offer them! -
Synergy 3105 Base reset to default - tech. Expert ...
Hi, I've had my Synergy 3105 for years and for me (with decent 1100mAh re-chargeable) it has been a great system i want to keep.
However Handset 2(HS2) developed a display problem then a catastrophic fault. I managed to get 3 more Synergy 3105 handsets then hit a problem registering them to the base station.
Because HS2 is faulty and effectively a 'lost' handset, the base station still thinks it is there, I cannot remove it because the original handset is faulty. Therefore, I can only register 4 handsets.
Does anybody know how I can reset the base station back to default, so it will forget everything it knows about the previous handset registrations?
I think I read that these units are supplied with a pre-registered Handset 1. As default. I am also curious to know if Handset 1 gets lost or is inoperable?
I suspect there may be a power up reset sequence using the base station 'page' button - but I haven't found it yet.
First correct answer gets the prize, because I think others having problems registering replacement phones and getting the 'searching' message may not realise what is going on (previous handsets still allocated).
Thanks - Vox
Solved!
Go to Solution.That was a useful post for resetting a base station to default settings, however it does create a problem.
It leaves the Handsets orphaned and they themselves need a reset.
I have 3 Synergy 3105 base stations for different lines in my house, all worked well and I was able to register 4 handsets with each of the three base stations as Base1 Base2 & Base 3 ( Each hanset support up to 4 base stations).
I had six handsets, two for each base station and all worked well for a while.
I had the same problem of the screens giving up and somehow I lost or forgot the passwords.
So I did the reset you prescribe for BASE1 which was fine for a NEW handset but now EXISTING Handsets see the reset base unit as a brand new one and are orphaned from the BASE1 station they WERE connected to .
I have no way of deleting the Handset from the BASE1 as it requires a Pin I do not have and a base station to connect to that no longer exists.
So if I do the reset you suggest I will have to buy new handsets as these orphaned handsets can only connect to one more Base station.
What I need is some sort of Key sequence that resets a handset to Factory but does not require a Pin -
Is it possible to change sequence value on monthly basis.
ex. I want to start sequence from 1to 1000 and then reset from 1 to 1000 after month.
for every month i want to reset sequence is it possible.
Thanks in advanceHi,
I agree with Gj. I think you should use dbms_scheduler to do this at the beginning of every month.
I don't like the idea of dropping and re-creating the sequence. You'll lose grants, and procedures that reference the sequence will become invalid.
You can't alter the actual value of the sequence, but you can temporarily alter the INCREMENT BY value to get the same result, as shown in the script below:
PROMPT ========== reset_seq procedure ==========
CREATE OR REPLACE PROCEDURE reset_seq
( in_seq_name IN VARCHAR2 -- Name of sequence to be reset
, in_new_val IN NUMBER := 1 -- Bew value
AUTHID CURRENT_USER
AS
-- reset_seq changes the value of the given sequence.
-- This assumes:
-- (a) no one else will use the sequence while this is running
-- (b) the INCREMENT BY value of the sequence is 1
-- (c) the MINVALUE value of the sequence is less than in_new_val
-- A little extra coding can fix (b) and (c)
current_val PLS_INTEGER;
get_txt VARCHAR2 (1000) := 'SELECT ' || in_seq_name || '.NEXTVAL'
|| ' FROM dual';
set_txt VARCHAR2 (1000) := 'ALTER SEQUENCE ' || in_seq_name
|| ' INCREMENT BY ';
BEGIN
EXECUTE IMMEDIATE get_txt INTO current_val;
EXECUTE IMMEDIATE set_txt || TO_CHAR (FLOOR ((in_new_val - 1) - current_val));
EXECUTE IMMEDIATE get_txt INTO current_val;
EXECUTE IMMEDIATE set_txt || '1';
END reset_seq
SHOW ERRORS
PROMPT ========== Creating sequence ==========
DROP SEQUENCE x_seq;
CREATE SEQUENCE x_seq
MINVALUE 0
NOCACHE
START WITH 1;
PROMPT ========== Using some values ==========
SELECT x_seq.NEXTVAL
FROM dual
CONNECT BY LEVEL <= 5;
PROMPT ========== Re-setting sequence ==========
EXECUTE reset_seq ('x_seq');
SELECT x_seq.NEXTVAL AS new_improved
FROM dual;The first two steps (creating the reset_seq procedure and creating the sequence) are done once, for all time.
The next step "using some value" simulates your normal work during the month.
At the beginning of every month, call reset_seq, as shown. -
Primary key, column, sequence : best practice.
Hi I was wondering when designing table should you limit the length of primary key.
Because if you have limited column length, and your adding and removing items than you have sequence gap, than you will need to resize column length and if their foreign key (resize them in foreign key relationship too) or you need to reset sequence to go back to the maximum (id).
WHat are the benefits and disbenefits of having limited column length. Is their way to restrict the maximum number of items without putting column length in their (inside the database) not the application.
Thanks.Unless you know the exact number of rows your table will have, it is not convenient to limit the size. Now it all depend on what you mean by limiting the size and which column type you are talking about.
Here I have some notes about --> Why is Varchar2 oversizing bad?, where I state this:
Apparently the same space consumption would be the same if a Varchar2(4) is used versus a Varchar2(4000), if you require one byte, then one byte will be allocated, and performance should be the same, but when taking a look at the performance statistics there are some surprises that arise.
When fetching information from Oracle, buffers and fetching structures are being prepared beforehand to be able to manage the maximum column lenght, applications such as toad may run out of memory trying to allocate resources to retrieve the information from an unnecessarily over sized varchar2 column.
The answer to your case is: you should better plan according to your actual requirements, if you oversize columns you will degrade performance and you will have memory issues on the long run. If you under size then you will have problems with maximum capacity in your tables and you will be forced to -most probably- perform online maintenance to your objects to resize them.
~ Madrid
http://hrivera99.blogspot.com/ -
Can a strored procedure contain Drop Sequence /Create Sequence statement?
I am trying to schedule a job to update the starting value of a sequence. So I need to write a strored procedure to drop and then recreate the sequence. But when i tried to cimpile the follwing stored procedue, it gave me the error "'DROP' is not a valid identifier". Is it illegal to have "Drop Sequence /Create Sequence " in a stored procedue? If this is true, is there any way to accomplish my task (simply recreate the same sequence with different starting value every month)? Thanks!
Begin
DROP SEQUENCE TEST_SEQ;
CREATE SEQUENCE TEST_SEQ
START WITH 0
MAXVALUE 999999999999
MINVALUE 0
NOCYCLE NOCACHE NOORDER;
EndIn general, it is a bad idea to try to encode information into a key because it
- complicates queries in the future
- complicates updates to the data in the future
- can easily be generated on the fly from other data elements
Inevitably, if you do something like what was proposed, you'll find out that the data encoded in the key gets out of date from the data stored in the row, that users are writing queries that do things like strip off the first 6 characters of the string in order to do date searches, and that users discover they want to be able to modify the data to fix the data that's encoded in the keys, which can be terribly expensive if there are child tables.
Rather than trying to do this, I would store a DATE value and a non-reset sequence. You can always generate the reference number for the user by doing a TO_CHAR on the DATE and concatenating the output of an appropriate ranking function. If the users decide that they need to correct the DATE of an event, the reference number will be updated automagically since it was never stored in the database. A number generated in the query can also be guaranteed to be gap-free, which tends to please users.
Justin -
Can we restart the sequence at any moment without define max val
Hi all
can we restart the sequence without define the max value
i am creating batch for month and in every month i never know how much batches i have i want when the month change then batch restart
thanks and regards
vikas singhalHi,
Refer to : http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1119633817597
http://www.jaredstill.com/content/reset-sequence.html
- Pavan Kumar N -
Can not create a sequence inside procedure
I have a procedure like this:
CREATE OR REPLACE PROCEDURE P_reset_Sequences AS
BEGIN
execute immediate '
DROP SEQUENCE ADMIN_AUTORESPONSES_SEQ';
execute immediate '
CREATE SEQUENCE ADMIN_AUTORESPONSES_SEQ
START WITH 1
INCREMENT BY 1
MINVALUE 1
NOCYCLE
NOCACHE
ORDER
END P_reset_Sequences;
When I execute this procedure to reset sequence ADMIN_AUTORESPONSES_SEQ, there an erro: insufficient privileges. But owner of this procedure has DBA privilege.
Pls, help me!There are two reasons to reset a sequence in code.
You could run out of numbers or you think you can use sequences as a gap free counter.
Running out of numbers is a problem every [3,000,000,000,000,000,000,000,000,000 years|Re: What kind of transaction in procedure? or thereabouts.
Looking at the sequence definition with NOCACHE , ORDER and an INCREMENT by 1 it appears the OP mistakenly believes you can use a sequence as a gap free counter ignoring rollbacks, exceptions and shutdowns amongst other things, when all those setting have really done is [make the sequence as slow as possible|http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:6393918681776].
Maybe you are looking for
-
Cleaning Dell LCD Monitor - What are current recommendations?
What are the current recommendations for cleaning a Dell LCD Monitor? I have always used 50% distilled water and 50% isopropyl alcohol and gently cleaned with a microfibre cloth. We have many different Dell LCD monitors in my workplace. George
-
firefox is the only browser on my laptop have no way to fix it firefox wont open periode so please how can i fix the probleme
-
How can I get Address Book Server to share contacts between users?
I want to have a Shared Address Book for the users on my installation of OS X Lion Server. Users will keep their own contacts individually but there are certain lists and contacts who need to be shared between users and I can't find any way of gettin
-
How do I select Target shadow color in curves and levels
On a tutorial I see that by double clicking on the shadow eyedropper in the curves dialog, I should get to the "Select target shadow color" dialog box. However, I only get a color dialog box. Any clues as to how I can change dialog boxes??
-
Illustrator installation with error.
I'm trying to do the installation of the illustrator but giving this error 82829s5 already checked the procedures that are reported, but still could not install the program.