Introduction to Variables Working with Variables

12-14 Oracle Fusion Middleware Developers Guide for Oracle Data Integrator Then in your package, you will simply drag and drop your variable and select the “Refresh Variable” option in the Properties panel. At runtime, the ODI agent will execute the SQL statement and assign the first returned value of the result set to the variable. – Explicitly setting the value in a package : You can also manually assign a value to your variable for the scope of your package. Simply drag and drop your variable into your package and select the “Set Variable” and “Assign” options in the Properties panel as well as the value you want to set. – Incrementing the value : Incrementing only applies to variables defined with a numeric data type. Drag and drop your numeric variable into the package and select the “Set Variable” and “Assign” options in the Properties panel as well as the desired increment. Note that the increment value can be positive or negative. – Assigning the value at runtime : When you start a scenario generated from a package containing variables, you can set the values of its variables. You can do that in the StartScenario command by specifying the VARIABLE=VALUE list. Refer to the OdiStartLoadPlan API command and the section Section 20.3.2, Executing a Scenario from a Command Line . How to create a Assign Variable step is covered in Setting a Variable . ■ Incrementing a numeric value : A Set Variable step of type Increment increases or decreases a numeric value by the specified amount. How to create a Set Variable step is covered in Setting a Variable . ■ Evaluating the value for conditional branching : An Evaluate Variable step acts like an IF-ELSE step. It tests the current value of a variable and branches in a package depending on the result of the comparison. For example, you can choose to execute interfaces A and B of your package only if variable EXEC_A_AND_B is set to “YES”, otherwise you would execute interfaces B and C. To do this, you would simply drag and drop the variable in your package diagram, and select the “Evaluate Variable” type in the properties panel. Evaluating variables in a package allows great flexibility in designing reusable, complex workflows. How to create an Evaluate Variable step is covered in Evaluating a Variable .

12.2.3.2 Using Variables in Interfaces

Variables can be used in interfaces in two different ways: 1. As a value for a textual option of a Knowledge Module. 2. In all Oracle Data Integrator expressions such as mappings, filters, joins, and constraints. To substitute the value of the variable into the text of an expression, precede its name by the character. The agent or the graphical interface will substitute the value of the variable in the command before executing it. The following example shows the use of a global variable named YEAR: Update CLIENT set LASTDATE = sysdate where DATE_YEAR = GLOBAL.YEAR DATE_YEAR is CHAR type Update CLIENT set LASTDATE = sysdate where DATE_YEAR = GLOBAL.YEAR DATE_YEAR is NUMERIC type The bind variable mechanism of the SQL language can also be used, however, this is less efficient, because the relational database engine does not know the value of the variable when it constructs the execution plan for the query. To use this mechanism, Working with Procedures, Variables, Sequences, and User Functions 12-15 precede the variable by the : character, and make sure that the datatype being searched is compatible with that of the variable. For example: update CLIENT set LASTDATE = sysdate where DATE_YEAR =:GLOBAL.YEAR You can drag-and-drop a variable into most expressions with the Expression Editor.

12.2.3.3 Using Variables in Object Properties

It is also possible to use variables as substitution variables in graphical module fields such as resource names or schema names in the topology. You must use the fully qualified name of the variable Example: GLOBAL.MYTABLENAME directly in the Oracle Data Integrator graphical modules field. Using this method, you can parameterize elements for execution, such as: ■ The physical names of files and tables Resource field in the datastore or their location Physical schemas schema data in the topology ■ Physical Schema ■ Data Server URL

12.2.3.4 Using Variables in Procedures

You can use variables anywhere within your procedures’ code as illustrated in the Table 12–4 . Table 12–3 Examples of how to use Variables in Interfaces Type Expression Mapping ‘PRODUCT_PREFIX’ || PR.PRODUCT_ CODE Concatenates the current project’s product prefix variable with the product code. As the value of the variable is substituted, you need to enclose the variable with single quotes because it returns a string. Join CUS.CUST_ID = DEMO.UID 1000000 + FF.CUST_NO Multiply the value of the UID variable of the DEMO project by 1000000 and add the CUST_NO column before joining it with the CUST_ID column. Filter ORDERS.QTY between MIN_QTY and MAX_QTY Filter orders according to the MIN_QTY and MAX_ QTY thresholds. Option Value TEMP_FILE_NAME: DEMO.FILE_NAME Use the FILE_NAME variable as the value for the TEMP_FILE_NAME option. Table 12–4 Example of how to use Variables in a Procedure Step ID: Step Type Step Code Description 1 SQL Insert into DWH.LOG_TABLE_ NAME Values 1, ‘Loading Step Started’, current_date Add a row to a log table that has a name only known at runtime 2 Jython f = open‘DWH.LOG_FILE_ NAME’, ‘w’ f.write‘Inserted a row in table s’ ‘DWH.LOG_ TABLE_NAME’ f.close Open file defined by LOG_ FILE_NAME variable and write the name of the log table into which we have inserted a row.