For some reason Oracle Sequence is skipping the first value. Here is an example of script.
drop sequence tseq;
drop table xyz;
create table xyz
(sno integer);
create sequence tseq
start with 1;
insert into xyz values (tseq.nextval);
select * from xyz;
Now the runtime of the script in SQL Developer:
drop sequence tseq succeeded.
drop table xyz succeeded.
create table succeeded.
create sequence succeeded.
1 rows inserted
SNO
----------------------
2
Why is it skipping the starting value 1. Is there something new in 11g that is causing it to skip the first value. I have many scripts and they all are having errors due to this issue.
I have Oracle 11g database home in my 64 bit Windows 7 machine. However, now i would like to install Oracle 10.2.0 client as well. I tried giving a separate location.
But for some reason, whenever i start the Setup and run the Administrator Type, the installation just skips without giving any errors. It just creates the inventory folder in the specified path. It goes to the Product-Specific Prerequisite Checks and exits without giving any warnings or errors.
I have created a trigger for after insert which updates a table when there is a row inserted in that table. The update is on a column which stores the application description along with the sequence number. Now my requirement is that sequence number should be unique only with in an application but not with in the table.Say the row entry can be as follows:
App_Desc Request_ID ----------------------- DEV 100 1 DEV 101 2 STG 100 3 STG 101 4
Here Request_ID is unique But the sequqnce thats created for DEV (100,101) should take an entry of 102 for the next entry for DEV and same applies for STG. So I have to use the same sequqnce for all the application.
1) Invoice Invoice_no number(8), Debtor varchar2(35), Invoice Date Date, Print Date Date, Currency varchar2(3), Total Amount Ex Number(11,2), Total Amount Vat Number(11,2), Total Amount Number(11,2), Status Varchar2(15),
The below trigger is running fine without any error ,but i wasn't able to perform the exact logic by the below trigger.IF, inserting multiple row then the SIVNUM field gets the same sequence number for each row , without incrementing the value for the next row.
Only the sequence value increases on the next set of row ow's inserted
Example (inserting 2 rows ) based on the below trigger:
I have round about 100 sequences in a schema. How can i identify that which sequences are not used for a long time. Or How can i identify the last date when that sequence is used.
In our production, we have two nodes in the cluster. We use the sequence for one of the main table for primary key. Our application is expecting sequence number increments along with created date time stamp. Right now sequences are cached for each node and it creates problem for the application. We would not like to use NOCACHE option because it causes performance issue.
This is the current scenario -
Transaction #1 on Node 1 - Seq ID 1 - Time Stamp 12:01 Transaction #2 on Node 2 - Seq ID 51 - Time Stamp 12:02 Transaction #3 on Node 1 - Seq ID 2 - Time Stamp 12:03
When I try to query based on the time stamp, primary should also go up. To be very clear on what I would like to have, please consider the following example.Without using NOCACHE option, I need to have the data in the following order.
Transaction #1 on Node 1 - Seq ID 1 - Time Stamp 12:01 Transaction #2 on Node 2 - Seq ID 2 - Time Stamp 12:02 Transaction #3 on Node 1 - Seq ID 3 - Time Stamp 12:03
In other words, sequence number should always increment along with the time.
I have Created sequence in oracle 10G and its working fine. its showing THE NUMBER IS 2
SQL> DECLARE NUM NUMBER; 2 BEGIN 3 select SERIAL_NO.NEXTVAL into num from dual; 4 DBMS_OUTPUT.PUT_LINE('THE NUMBER IS ' ||NUM); 5 END; 6 / THE NUMBER IS 2
PL/SQL procedure successfully completed.When i execute this code in oracle 11G then it does not show output.
SQL> DECLARE NUM NUMBER; 2 BEGIN 3 NUM :=SERIAL_NO.NEXTVAL; 4 DBMS_OUTPUT.PUT_LINE('THE NUMBER IS ' ||NUM); 5 END; 6 /
PL/SQL procedure successfully completed. SQL> Why this is not showing output as THE NUMBER IS .
I created a Table with a single column varchar2.. in which I wanted to insert value like 'BBBBAB1'... till 'BBBBAB100'
Created a sequence starting with 1...
and inserted single row, and multiple rows using loop also; by using below code -
insert into Trans SELECT CONCAT('BBBBAB', Trans1.NEXTVAL) from dual;
but whenever I see the values they are not as required ... 'BBBBAB1' but one character 'B' is missing, and the values populating are 'BBBAB1'.. 'BBBAB100'
I have a table called "Subjects" which lists subjects to match with notations in another table I have created a simple sequence (CREATE sequence subjectid) to created the subject id for the table. But I notice that if there is a skip in the date, the sequence increments automatically when I am not even using it. It even appears to be incrementing even when I am not doing any database activity.
This is not an issue of data integrity, because the values in the subject_id column do not need to be sequential, they just need to be unique. But it really has me curious. I created another table called "keep_track" to keep track of what is happening:
Can we use the sequence.nextval,sequence.currval inside case block.
CREATE TABLE EQUALITY_TEST(NUM1 NUMBER, NUM2 NUMBER, SEQ NUMBER); INSERT INTO EQUALITY_TEST VALUES ( 2 ,0 , NULL); INSERT INTO EQUALITY_TEST VALUES ( 2 ,2 , NULL); INSERT INTO EQUALITY_TEST VALUES ( 2 ,2 , NULL); INSERT INTO EQUALITY_TEST VALUES ( 12 ,2 , NULL); INSERT INTO EQUALITY_TEST VALUES ( 12 ,12 , NULL); INSERT INTO EQUALITY_TEST VALUES ( 12 ,12 , NULL); CREATE SEQUENCE SEQ_TEMP START WITH 100 INCREMENT BY 1;
Now i need to update SEQ column with SEQ_TEMP sequence. When NUM1,NUM2 values are unequal sequence should be incremented otherwise need to use the same sequence number(CURRVAL)
I have tried like this
UPDATE EQUALITY_TEST SET SEQ= CASE WHEN NUM1=NUM2 THEN SEQ_TEMP.NEXTVAL ELSE SEQ_TEMP.CURRVAL END ; SELECT * FROM EQUALITY_TEST;
I'm having some difficulty getting a simple SQL statement to work. It uses bind variables, but has a problem when I introduce a sequence:
INSERT INTO AE_MASTER.STAGE_USAGE (STAGE_USAGE_ID, ANIMAL_USAGE_ID_FK) VALUES (AE_MASTER.AE_GENERIC_SEQ.NEXTVAL, :dummy)
==> ORA-00942: table or view does not exist
But if I remove the sequence, it works:
INSERT INTO AE_MASTER.STAGE_USAGE (STAGE_USAGE_ID, ANIMAL_USAGE_ID_FK) VALUES (1, :dummy)
==> Success
So you might think there is a problem with the sequence, but if I use a name that doesn't exist, it tells me so:
INSERT INTO AE_MASTER.STAGE_USAGE (STAGE_USAGE_ID, ANIMAL_USAGE_ID_FK) VALUES (xxxAE_MASTER.AE_GENERIC_SEQ.NEXTVAL, :dummy)
==> ORA-02289: sequence does not exist
So I'm a bit stumped as to why it's not working! Is it not possible to use sequences with bind variables?
In the past I have gotten around this by using a SELECT statement to get the sequence number then following it with the INSERT statement, but this time I'd really like to get it all done in the same statement if possible.
I have a following select statement where I am not generating a sequence in any of these WHERE clause, GROUP BY or ORDER BY clause, DISTINCT clause, along with a UNION or INTERSECT or MINUS or sub-query.
I have query like this
"SELECT AER_ID_TEMP.AER_ID, AER_ID_TEMP.D__PRNO, AER_ID_TEMP.D__PCNT, CAST((select char_value from aris_param_data where param_id = 101)||seq_record_id.nextval AS INT) as RECORD_ID FROM AER_ID_TEMP"
but still encountering a error "ORA-02287 sequence number not allowed"
i would like to create a sequence inside a dml trigger. Is it possible? I created a trigger and it is compiled sucessfully.
create or replace trigger tri_update_test after delete on test declare pragma autonomous_transaction;
[code]...
trigger created sucessfully.And i try to delete data from the test
delete from test where id=5;
Output:
ERROR at line 1: ORA-01031: insufficient privileges ORA-06512: at "SCOTT.TRI_UPDATE_TEST", line 4 ORA-04088: error during execution of trigger 'SCOTT.TRI_UPDATE_TEST'
I created a stored procedure(A) in user1@db1. This stored procedure will insert data from db1 to tables in user2@db2 using synonyms created in user1@db1 referencing table at user2@db2.
In the stored procedure (A),
insert into synonym select seq_xx.nextval from table@db1;
Then I will execute (A) in user2@db1. Execute right on (A) is given to user2@db1.Select and insert grants on db2 tables are given to user1@db1. Seq is created in db1. Compilation is successful, however when i execute (A) it has an error of
ORA-02289: sequence does not exist ORA-02063: preceding line from db1 ORA-02063: preceding 2 lines from db2
In oracle is it possible to find if a sequence was reset? I know my sequence was reset, looking at the nextval of my sequence, but is there an oracle log or anything which proves that sequence was reset ?
I'd like to have a conditional that only gets the next value from a sequence is the current (or supplied) value is null.
Here are some trivial examples:
CREATE SEQUENCE ts MINVALUE 1 START WITH 1 INCREMENT BY 1; SELECT ts.NEXTVAL FROM DUAL; SELECT COALESCE(ts.CURRVAL, ts.NEXTVAL) FROM DUAL; SELECT NVL(ts.CURRVAL, ts.NEXTVAL) FROM DUAL; SELECT CASE WHEN ts.CURRVAL IS NOT NULL THEN ts.CURRVAL ELSE ts.NEXTVAL END FROM DUAL;
Ideally multiple executions of any of these (or a better one of your design) should return the same value from the sequence, but mine do not.