-- printed: 2/6/2016 4:02:15 AM
Run an Oracle package from SQL Server Integration Services
Written By: Daniel Calbimonte -- 9/14/2012
An Oracle Package is similar to a SQL Server SQL Server Stored Procedure. If you want to run an Oracle Package and then execute a web service, copy files or folders, a sequence of tasks, etc. you may need to use SQL Server Integration Services (SSIS). SSIS is a powerful tool included with SQL Server to integrate data from different databases. Typically, the Oracle Package sequences are created in the Oracle Warehouse Builder, but sometimes we need to combine Oracle code with some Microsoft tasks. In this case, SSIS is a viable option. So in this tip we will show you how to call an Oracle Package from an SSIS Package.
In the first example, we are going to run an Oracle package without parameters in SQL Server Integration Services. The second example will run a package with parameters.
- I am assuming that you already know how to create a connection to Oracle. If you do not, read this tip - Export SQL Server Data to Oracle using SSIS.
- You need to have SSIS and Oracle installed. In my case I tested SQL Server 2012 with the Oracle client 11g, but the examples in this tip should work with earlier versions.
- You need to have some Oracle packages already created. If you do not know how to create Oracle packages, refer to this link: Oracle packages.
Getting Started with calling an Oracle Package from SQL Server Integration Services
In this example, we are going to run the following Oracle package with the Execute SQL Task:
Lets start an Integration Services project with the SQL Server Data Tools (SSDT) in SQL Server 2012 or the Business Intelligence Development Studio (BIDS) in SQL Server 2008 or 2005:
- Create a connection to your Oracle server.
- In the Control Flow tab drag and drop the Execute SQL Task. This task let's us execute SQL tasks to Excel, OLE DB providers, ADO.NET providers and ODBC. You can connect to mySQL, Oracle, Postgres, etc. database with this powerful task.
- Double click on the Execute SQL Task and select the connection to Oracle which you already created.
- Double click on the SQLStatement ellipsis and write the following code:
- In the example above, the package name is PKG_EMPE_DIM.ETL_ALL_EMPLE_DIM. The BEGIN, semicolons and END are very important in Oracle.
- That is all! If you run the SSIS package, by pressing the green play button, the Oracle package will be executed.
- The package status can be verified in the Progress tab as shown below.
Running an Oracle Package from SSIS with parameters
You can also pass parameters from SSIS to the Oracle Package.
In this example we are going to run the following package with these parameters:
Now, if you want to run a package with parameters, you need to add a few items to the existing SSIS package we just created:
- On the Control Flow tab, double click on the Execute SQL Task then click on the SQLStatement ellipsis in order to modify the code being issued.
- In the "Enter SQL Query" text box, write the package name and use the question mark for the parameters. In this example this package has 4 parameters.
- I am using SQL Server 2012, I will go to the parameters tab to work with the variables. If you are using earlier versions of SSIS, go to the SSIS menu and click Variables.
- Add the needed parameters (variables) with the correct data types. In my scenario the parameters are varchars so I am using the string data type. You also need to add the parameter values.
The following table maps the SSIS and Oracle data types:
|Oracle Data Types
SSIS Parameter Data Types
|TIMESTAMP, DATE, INTERVAL
||Int16, Int32, Int64|
|CHAR, VARCHAR2, NVARCHAR2, NCHAR
- Now, with the Execute SQL Task, we need to go to the Parameter Mapping interface to map the question marks parameters created in step 3. Here is the interface:
- I chose the parameters in the Parameter Mapping interface. The first question mark in step 2 above belongs to parameter name 0, the second question mark belongs to the second which is parameter name 1 and so on. In this example the Data Type is nvarchar. The parameter name is very important here. For more information about parameter and OLEDB click here. Keep in mind that OLEDB provider uses numbers as a parameter names. The first parameter is named 0 and the second 1 and so on. Other providers like ODBC do not use numbers as parameter names.
- The following table will help you to map SSIS variables in the Parameter Mapping interface in the Execute SQL Task:
|SSIS Parameter Data Types
Execute SQL Task parameter mapping data types
|Int16, Int32, Int64
- Finally, you have your package ready to run with the parameters. Press the green play button.
- In order to see the results, you can setup log files in SSIS. To configure this feature click on the package's control flow tab, then select the SSIS menu and the Logging option. In the interface below select the option for "SSIS log provider for Text files" and review the log once the execution is complete.
- Additionally, you can also configure error handling using the Event Handler Tab. We will explain more details about error handling and SSIS logging in future tips:
As a final note, keep in mind the parameters in this example were configured with specific values for design time testing. To pass parameters into an SSIS Package at runtime, you can use the DTEXEC command to run the SSIS package with the required parameters.
Additional SSIS FunctionalityKeep in mind you can execute Oracle procedures, packages and functions with SSIS and combine them with other tasks like sending email or the file system task to extend the functionality of your packages. In future tips we will cover these topics in more detail.
- Review these links for more information: