In the Project view of the Designer Navigator, select the procedure you want to

12-12 Oracle Fusion Middleware Developers Guide for Oracle Data Integrator Substitution methods such as getObjectName in the syntax of your query expression.

3. Click Testing query on the DBMS to check the syntax of your expression.

4. Click Refresh to test the variable by executing the query immediately. If the

variable action is set to Historize or Latest Value, you can view the returned value on the History tab of the Variable editor.

5. From the File menu, click Save.

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

12.2.3 Using Variables

Using Variables is highly recommended to create reusable packages or packages with a complex conditional logic, interfaces and procedures. Variables can be used everywhere within ODI. Their value can be stored persistently in the ODI Repository if their action type is set to “Historize” or “Last Value”. Otherwise, with an action type of “Non-Persistent”, their value will only be kept in the memory of the agent during the execution of the current session. This section provides an overview of how to use variables in Oracle Data Integrator. Variables can be used in the following cases: ■ Using Variables in Packages ■ Using Variables in Interfaces ■ Using Variables in Object Properties ■ Using Variables in Procedures ■ Using Variables within Variables ■ Using Variables in the Resource Name of a Datastore ■ Passing a Variable to a Scenario ■ Generating a Scenario for a Variable Variable scope Use the Expression editor to refer to your variables in Packages, integration interfaces, and procedures. When you use the Expression editor the variables are retrieved directly from the repository. You should only manually prefix variable names with GLOBAL or the PROJECT_ CODE, when the Expression editor is not available. Referring to variable MY_VAR in your objects should be done as follows: ■ MY_VAR: With this syntax, the variable must be in the same project as the object referring to it. Its value will be substituted. To avoid ambiguity, consider using fully qualified syntax by prefixing the variable name with the project code. Note: It is advised to use the Expression editor when you refer to variables. By using the Expression editor, you can avoid the most common syntax errors. For example, when selecting a variable in the Expression editor, the variable name will be automatically prefixed with the correct code depending on the variable scope. Refer to Variable scope for more information on how to refer to your variables. Working with Procedures, Variables, Sequences, and User Functions 12-13 ■ MY_PROJECT_CODE.MY_VAR: Using this syntax allows you to use variables by explicitly stating the project that contains the variable. It prevents ambiguity when 2 variables with the same name exist for example at global and project level. The value of the variable will be substituted at runtime. ■ GLOBAL.MY_VAR: This syntax allows you to refer to a global variable. Its value will be substituted in your code. Refer to section Global Objects for details. ■ Using “:” instead of “”: You can use the variable as a SQL bind variable by prefixing it with a colon rather than a hash. However this syntax is subject to restrictions as it only applies to SQL DML statements, not for OS commands or ODI API calls and using the bind variable may result in performance loss. It is advised to use ODI variables prefixed with the character to ensure optimal performance at runtime. – When you reference an ODI Variable prefixed with the : character, the name of the Variable is NOT substituted when the RDBMS engine determines the execution plan. The variable is substituted when the RDBMS executes the request. This mechanism is called Binding. If using the binding mechanism, it is not necessary to enclose the variables which store strings into delimiters such as quotes because the RDBMS is expecting the same type of data as specified by the definition of the column for which the variable is used. For example, if you use the variable TOWN_NAME = :GLOBAL.VAR_TOWN_ NAME the VARCHAR type is expected. – When you reference an ODI variable prefixed with the character, ODI substitutes the name of the variable by the value before the code is executed by the technology. The variable reference needs to be enclosed in single quote characters, for example TOWN = GLOBAL.VAR_TOWN. The call of the variable works for OS commands, SQL, and ODI API calls.

12.2.3.1 Using Variables in Packages

Variables can be used in packages for different purposes: ■ Declaring a variable : When a variable is used in a package or in certain elements of the topology that are used in the package, it is strongly recommended that you insert a Declare Variable step in the packaget. This step explicitly declares the variable in the package. How to create a Declare Variable step is covered in Declaring a Variable . Other variables that you explicitly use in your packages for setting, refreshing or evaluating their values do not need to be declared. ■ Refreshing a variable from its SQL SELECT statement : A Refresh Variable step allows you to re-execute the command or query that computes the variable value. How to create a Refresh Variable step is covered in Refreshing a Variable . ■ Assigning the value of a variable : A Set Variable step of type Assign sets the current value of a variable. In Oracle Data Integrator you can assign a value to a variable in the following ways: – Retrieving the variable value from a SQL SELECT statement : When creating your variable, define a SQL statement to retrieve its value. For example, you can create a variable NB_OF_OPEN_ORDERS and set its SQL statement to: select COUNT from =odiRef.getObjectNameL,ORDERS,D where STATUS = ‘OPEN’.