Run an Oracle package from SQL Server Integration Services

By:   |   Comments (10)   |   Related: More > Integration Services Oracle


Problem

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.

Solution

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.

Requirements

  • 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:

BEGIN PKG_EMPE_DIM.ETL_ALL_EMPE_DIM;
END;

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:

  1. Create a connection to your Oracle server.
    connections
  2. 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.
    connections
  3. Double click on the Execute SQL Task and select the connection to Oracle which you already created.
    Open the SQL Server Management Studio
  4. Double click on the SQLStatement ellipsis and write the following code:
    BEGIN PKG_EMPE_DIM.ETL_ALL_EMPLE_DIM;
    END;
    
    Backup the Multidimentional Database
  5. 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.
  6. That is all! If you run the SSIS package, by pressing the green play button, the Oracle package will be executed.
    Save the file as
  7. The package status can be verified in the Progress tab as shown below.
    Save the file as

 

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:

BEGIN TRCKNG_FCT.ETL_STG_AR_ADTNL_TRCKNG_FACT('20120501','20120501','N','D');
END;

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:

  1. 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.
    Specify the backup path and options
  2. 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.
    Save the script in a different path.
  3. 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.
  4. 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.
    Script Action to New Query Window

    The following table maps the SSIS and Oracle data types:

    Oracle Data Types

    SSIS Parameter Data Types

    RAW byte
    date datetime
    TIMESTAMP, DATE, INTERVAL datetime
    NUMBER, INT Int16, Int32, Int64
    FLOAT, REAL float
    CHAR, VARCHAR2, NVARCHAR2, NCHAR string

  5. 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:
    Save the file as
  6. 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.
  7. 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

    byte BYTE
    datetime DB_DATE
    Int16, Int32, Int64 LONG
    float FLOAT

  8. Finally, you have your package ready to run with the parameters.   Press the green play button.
    Save the file as
  9. 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.
    log ssis
  10. 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:
    log ssis

 

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 Functionality

Keep 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.
Save the file as
Next Steps


sql server categories

sql server webinars

subscribe to mssqltips

sql server tutorials

sql server white papers

next tip



About the author
MSSQLTips author Daniel Calbimonte Daniel Calbimonte is a Microsoft SQL Server MVP, Microsoft Certified Trainer and 6-time Microsoft Certified IT Professional. Daniel started his career in 2001 and has worked with SQL Server 6.0 to 2022. Daniel is a DBA as well as specializes in Business Intelligence (SSIS, SSAS, SSRS) technologies.

This author pledges the content of this article is based on professional experience and not AI generated.

View all my tips



Comments For This Article




Tuesday, May 10, 2022 - 4:26:48 PM - saurabh Back To Top (90076)
What about if we have 4 input parameters and 2 output parameters, It always rerun a single records. How to pick that value in a variable and use it further?

Thursday, August 11, 2016 - 8:41:32 AM - Daniel Back To Top (43100)

In my experience nothing is obvious. A simple character can frustrate all the job.


Thursday, August 11, 2016 - 3:52:59 AM - Paul Marks Back To Top (43099)

 Hi

Thank you for the article i have found this very useful.

I would like to add and answer a question (i had the same problem)

I have a Oracle Stored procedure that has 8 input params and 1 output

The syntax i used was

Begin

   Exec Sp (?,?,?,?,?,?,?,?,?)

End

 

In the Parameter mapping of the Execute SQL Task i have the output parameter direction as output and all the other as IN all mapped to respective Variables

This may of seemed obvious but i struggled for ages.

 

With Kind Regards

Paul

 

 

 

 

 

 


Thursday, July 14, 2016 - 11:20:04 AM - Mark Back To Top (41891)

 Thanks MSSQLTips author Daniel Calbimonte Daniel, very clear and concise.


Thursday, April 23, 2015 - 4:57:40 AM - sunil Back To Top (37004)

Source (oracle), Destination (Sql)  in ssis package , Need to run the command line like

 

Sql looks like the below

 

echo START OF Mapping PKG_CTRY LOAD.

 

CD E:\Q2O\ssis_pkg\Mapping_Flow\Mapping_Flow

 

 

 

cd C:\Program Files\Microsoft SQL Server\110\DTS\Binn

 

dtexec /FILE "E:\Q2O\ssis_pkg\Mapping_Flow\Mapping_Flow\PKG_CTRY.dtsx" /conn "g4w9174.americas.hpqcorp.net,20485.TRANS.q2ouser1";"\"Data Source=g4w9174.americas.hpqcorp.net,20485;User ID=q2ouser1;Password=Q2O_User2015;Initial Catalog=TRANS;Provider=SQLNCLI11.1;Persist Security Info=True;Auto Translate=False;\""

 

 

 

if %ERRORLEVEL% EQU 0 (

 

echo Mapping PKG_CTRY LOAD COMPLETED

 

 ) else (

 

echo Mapping PKG_CTRY LOAD FAILED, CHECK THE LOG FILE FOR REASON OF FAILURE.

 

)

 

PAUSE

 

 

Need in Oracle   ?

 

 


Friday, September 12, 2014 - 6:58:59 PM - Edward Back To Top (34516)

Excelent post!!

Is it posible to execute a procedure with an out ref cursor?

Thanks.


Thursday, August 14, 2014 - 7:01:12 PM - Fernando Back To Top (34143)

Hello.

Could you explain the correct form to call stored procedures in oracle with output parameter, please?....

Thanks for your help.

 


Friday, May 9, 2014 - 3:01:21 PM - np Back To Top (30706)

how can i write two oracle sql update statements in exeute sql task in SSIS 2008 ? 

I am writing like ,

UPDATE .............. ;

 

update ............... ;

 

this is not working. throwing below error

[Execute SQL Task] Error: Executing the query "

" failed with the following error: "ORA-00911: invalid character". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.

 
any help will be appreciated! Thanks

Tuesday, December 24, 2013 - 10:46:25 PM - Deepak Khattar Back To Top (27881)

Hi,

When I run the package with connection provider as "ORACLE Provider for OLE DB",  every things works fine but my log file show 

"Warning: Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done." The warning is appearing after "Validation is Completed".  Error is appearing irrespective of using a parameter or simple delete statement. What could be the reason? 

 

 

SAMPLE Script 1

-----------------

BEGIN

KC_PAYMENT.VOID_PAYMENT(99,TO_DATE('2011/01/01','YYYY/MM/DD'),?,?);

END;

 

SAMPLE Script 2

-----------------

begin

delete from KC.kc_payment_stg;

 

end;

 

Sunday, September 16, 2012 - 5:28:15 AM - vishal Back To Top (19522)

 

Yes it is best















get free sql tips
agree to terms