Create three variables in your EDW project:

Working with Procedures, Variables, Sequences, and User Functions 12-21

5. Type in the Native Sequence Name or click the browse button to select a sequence

from the list pulled from the data server.

6. If you clicked the Browse button, in the Native Sequence Choice dialog, select a

Context to display the list of sequences in this context for your logical schema.

7. Select one of these sequences and click OK.

8. From the File menu, click Save.

The sequence appears in the Projects or Others tree in Designer Navigator.

12.3.3 Using Sequences and Identity Columns

In order to increment sequences, the data needs to be processed row-by-row by the agent. Therefore, using sequences is not recommended when dealing with large numbers of records. In this case, you would use database-specific sequences such as identity columns in Teradata, IBM DB2, Microsoft SQL Server or sequences in Oracle. The sequences can be used in all Oracle Data Integrator expressions, such as in: ■ Mappings, ■ Filters, ■ Joins, ■ Constraints, ■ ... Sequences can be used either as: ■ A substituted value, using the SEQUENCE_NAME_NEXTVAL syntax ■ A bind variable in SQL statements, using the :SEQUENCE_NAME_NEXTVAL syntax Using a sequence as a substituted value A sequence can be used in all statements with the following syntax: SEQUENCE_ NAME_NEXTVAL With this syntax, the sequence value is incremented only once before the command is run and then substituted by its valued into the text of the command. The sequence value is the same for all records. Using a sequence as a bind variable Only for SQL statements on a target command of a KM or procedure, sequences can be used with the following syntax: :SEQUENCE_NAME_NEXTVAL With this syntax, the sequence value is incremented, then passed as a bind variable of the target SQL command. The sequence value is incremented in each record processed by the command. The behavior differs depending on the sequence type: ■ Native sequences are always incremented for each processed record. ■ Standard and specific sequences are resolved by the run-time agent and are incremented only when records pass through the agent. The command in a KM or procedure that uses such a sequence must use a SELECT statement on the source command and an INSERT or UPDATE statement on the target command rather than a single INSERTUPDATE... SELECT in the target command. For example: 12-22 Oracle Fusion Middleware Developers Guide for Oracle Data Integrator ■ In the SQL statement insert into fac select :NO_FAC_NEXTVAL, date_ fac, mnt_fac the value of a standard or specific sequence will be incremented only once, even if the SQL statement processes 10,000 rows, because the agent does not process each record, but just sends the command to the database engine. A native sequence will be incremented for each row. ■ To increment the value of a standard or specific sequence for each row, the data must pass through the agent. To do this, use a KM or procedure that performs a SELECT on the source command and an INSERT on the target command: SELECT date_fac, mnt_fac on the source connection INSERT into FAC ORDER_NO, ORDER_DAT, ORDER_AMNT values :NO_FAC_NEXTVAL, :date_fac, :mnt_fac on the target connection Sequence Scope Unlike for variables, you do not need to state the scope of sequences explicitly in code.

12.3.3.1 Tips for Using Standard and Specific Sequences

To make sure that a sequence is updated for each row inserted into a table, each row must be processed by the Agent. To make this happen, follow the steps below:

1. Make the mapping containing the sequence be executed on the target.

2. Set the mapping to be active for inserts only. Updates are not supported for

sequences.

3. If you are using an incremental update IKM, you should make sure that the

update key in use does not contain a column populated with the sequence. For example, if the sequence is used to load the primary key for a datastore, you should use an alternate key as the update key for the interface.

4. If using Oracle Data Integrator sequences with bind syntax :SEQUENCE_

NAME_NEXTVAL, you must configure the data flow such that the IKM transfers all the data through the agent. You can verify this by checking the generated integration step in Operator. It should have separate INSERT and SELECT commands executed on different connections, rather than a single SELECT...INSERT statement. Limitations of Sequences Sequences have the following limitations: ■ A column mapped with a sequence should not be checked for not null. ■ Similarly, static control and flow control cannot be performed on a primary or alternate key that references the sequence.

12.3.3.2 Identity Columns

Certain databases also natively provide identity columns, which are automatically populated with unique, self-incrementing values. When populating an identity column, you should follow these steps: 1. The mapping loading the identity column should be blank and inactive. It should not be activated for inserts or updates.