Skip to main content
Solved

I am inserting entries in two Oracle tables. I want to relate the tables based on primary key (ID). This ID is generated as a sequence in the writer. Is there a way I can get the expected "netxval" ID, so I can create the relation?


I am inserting entries in two Oracle tables. I want to relate the two tables based on primary key (ID). This ID is generated as a sequence in the writer. Is there a way I can get the expected "netxval" ID, so I can set the relation ID-attribute before insertion? Or can I do this in another way?

Best answer by erik_jan

Instead of getting the Nextval of the sequence in the writer, you can get it earlier using a SQLExecutor transformer and the SQL statement: Select <mysequence>.nextval as ID from Dual.

Then you can use this ID attribute to write to the table and the relating table.

View original
Did this help you find an answer to your question?

5 replies

erik_jan
Contributor
Forum|alt.badge.img+17
  • Contributor
  • Best Answer
  • June 27, 2018

Instead of getting the Nextval of the sequence in the writer, you can get it earlier using a SQLExecutor transformer and the SQL statement: Select <mysequence>.nextval as ID from Dual.

Then you can use this ID attribute to write to the table and the relating table.


Forum|alt.badge.img+2
erik_jan wrote:

Instead of getting the Nextval of the sequence in the writer, you can get it earlier using a SQLExecutor transformer and the SQL statement: Select <mysequence>.nextval as ID from Dual.

Then you can use this ID attribute to write to the table and the relating table.

@erik_jan will using SQLExecutor to make a query for every feature impact the data load performance? I'm not very strong in SQL, but I wonder if there is a way to do this after the data load completes. Perhaps loading 'temporary Id's into the primary & foreign key fields (using Counter), and then replacing them in bulk with the <sequence> using SQLExecutor after the data load completes.

 


erik_jan
Contributor
Forum|alt.badge.img+17
  • Contributor
  • June 27, 2018
markatsafe wrote:
@erik_jan will using SQLExecutor to make a query for every feature impact the data load performance? I'm not very strong in SQL, but I wonder if there is a way to do this after the data load completes. Perhaps loading 'temporary Id's into the primary & foreign key fields (using Counter), and then replacing them in bulk with the <sequence> using SQLExecutor after the data load completes.

 

Yes @MarkAtSafe, It will slow down the workspace. And faster (but not easier) ways are available.

 

For a huge dataset I used a different approach: read the next sequence value, use a Counter to add to that number, Insert the data and then re-create the sequence with a new value (adding the count from the Counter). But this relies on nobody else using the sequence in the meantime and is tricky.

 

And using staging tables, having the database add the ID from the sequence is also an option (if you are good with SQL or PL/SQL).

 

But for smaller datasets I use the SQLExecutor (slower, but easier to implement).

 


Forum|alt.badge.img+2
erik_jan wrote:
Yes @MarkAtSafe, It will slow down the workspace. And faster (but not easier) ways are available.

 

For a huge dataset I used a different approach: read the next sequence value, use a Counter to add to that number, Insert the data and then re-create the sequence with a new value (adding the count from the Counter). But this relies on nobody else using the sequence in the meantime and is tricky.

 

And using staging tables, having the database add the ID from the sequence is also an option (if you are good with SQL or PL/SQL).

 

But for smaller datasets I use the SQLExecutor (slower, but easier to implement).

 

Perfect. Thanks

 

 


Thanks a lot


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings