
Anonymous
Not applicable
2015-05-28
08:53 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[resolved] Oracle Sequence current value
Hi,
I have a table and its primary key is generated with oracle sequence.
In my case I am inserting few columns in that table.(I gave sequence in additional columns ... I worked)
after few operations on data i need to update few columns on the same record. In order to do that I need current value of oracle_sequence .(as its my primary key)
Is that possible???
I know i can do it with join.But I need current value of oracle_sequence.
when i try "sequence.currval" i get
Thanks,
Pankaj
I have a table and its primary key is generated with oracle sequence.
In my case I am inserting few columns in that table.(I gave sequence in additional columns ... I worked)
after few operations on data i need to update few columns on the same record. In order to do that I need current value of oracle_sequence .(as its my primary key)
Is that possible???
I know i can do it with join.But I need current value of oracle_sequence.
when i try "sequence.currval" i get
ORA-00957: duplicate column name
Thanks,
Pankaj
1,059 Views
1 Solution
Accepted Solutions

Anonymous
Not applicable
2015-05-29
06:53 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can use the tOracleInput component for this. Change the query to ....
...and make sure you set the schema to be one column of a numeric type
"Select seq.nextval as keyNum
From DUAL"
...and make sure you set the schema to be one column of a numeric type
1,059 Views
6 Replies

Anonymous
Not applicable
2015-05-28
05:45 PM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No this is a very bad idea because you can never be sure anybody else is selecting another value of the sequence.
The only reliable way is to select a value from the sequence with seq.nextval und keep this value in your job for further processing. Anything else is a design flaw!
The only reliable way is to select a value from the sequence with seq.nextval und keep this value in your job for further processing. Anything else is a design flaw!
1,059 Views

Anonymous
Not applicable
2015-05-29
02:36 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Thanks for your reply.
according to my knowledge i can get same sequence using seq.currval for that session.In order to get currval i have to first use seq.nextval for that session.(I had same doubt as you so i performed a simple test in oracle DB).
I am not hung up on currval i just need same sequence i used to insert that record so i can use it in update query.
How can i store sequence.nextval in global variable???
an example will really help.
Thanks,
Pankaj
Thanks for your reply.
according to my knowledge i can get same sequence using seq.currval for that session.In order to get currval i have to first use seq.nextval for that session.(I had same doubt as you so i performed a simple test in oracle DB).
I am not hung up on currval i just need same sequence i used to insert that record so i can use it in update query.
select a value from the sequence with seq.nextval and keep this value in your job for further processing. Anything else is a design flaw!
How can i store sequence.nextval in global variable???
an example will really help.
Thanks,
Pankaj
1,059 Views

Anonymous
Not applicable
2015-05-29
05:04 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you want to use the sequence for several things inside your job, I would get the next sequence number (as jlolling suggested) using a query against "DUAL". Return that value to the job and use a tSetGlobalVar component to store the value. The tSetGlobalVar will store the value in a global HashMap called "globalMap". You can store values in this using the tSetGlobalVar component or manually using a bit of Java (see below)...
You can retrieve these values practically anywhere in Talend using a variant on the code below....
In the example above, we are casting the value to a String as all values are stored as Objects. You will need to cast to whatever type you start with. The "VariableKey" is the name of the value.
This should allow you to retrieve the value once from the sequence and use it as many times as you wish in the Job.
globalMap.put("VariableKey", variable);
You can retrieve these values practically anywhere in Talend using a variant on the code below....
((String)globalMap.get("VariableKey"));
In the example above, we are casting the value to a String as all values are stored as Objects. You will need to cast to whatever type you start with. The "VariableKey" is the name of the value.
This should allow you to retrieve the value once from the sequence and use it as many times as you wish in the Job.
1,059 Views

Anonymous
Not applicable
2015-05-29
06:46 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
how to fire query to DB.what component should i use???
(I know to to get data from table (i knw toracleinput))
Thanks,
Pankaj
how to fire query to DB.what component should i use???
(I know to to get data from table (i knw toracleinput))
Thanks,
Pankaj
1,059 Views

Anonymous
Not applicable
2015-05-29
06:53 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can use the tOracleInput component for this. Change the query to ....
...and make sure you set the schema to be one column of a numeric type
"Select seq.nextval as keyNum
From DUAL"
...and make sure you set the schema to be one column of a numeric type
1,060 Views

Anonymous
Not applicable
2015-05-29
09:23 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
It worked!!
thanks rhall and jlolling for your help.
regards,
Pankaj
It worked!!
thanks rhall and jlolling for your help.
regards,
Pankaj
1,059 Views
