Automate Oracle Integration Tasks from PowerShell

Jerod Johnson
Jerod Johnson
Director, Technology Evangelism
Are you in search of a quick and easy way to access Oracle data from PowerShell? This article demonstrates how to utilize the Oracle Cmdlets for tasks like connecting to Oracle data, automating operations, downloading data, and more.

The CData ADO.NET Provider for Oracle is a standard ADO.NET Provider that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to Oracle.

ADO.NET Provider

The ADO.NET Provider provides a SQL interface for Oracle; this tutorial shows how to use the Provider to create, retrieve, update, and delete Oracle data.

Once you have acquired the necessary connection properties, accessing Oracle data in PowerShell can be enabled in three steps.

To connect to Oracle, you'll first need to update your PATH variable and ensure it contains a folder location that includes the native DLLs. The native DLLs can be found in the lib folder inside the installation directory. Once you've done this, set the following to connect:

  • Port: The port used to connect to the server hosting the Oracle database.
  • User: The user Id provided for authentication with the Oracle database.
  • Password: The password provided for authentication with the Oracle database.
  • Service Name: The service name of the Oracle database.
  1. Load the provider's assembly:

    [Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Oracle\lib\System.Data.CData.OracleOCI.dll")
  2. Connect to Oracle:

    $conn= New-Object System.Data.CData.OracleOCI.OracleOCIConnection("User=myuser;Password=mypassword;Server=localhost;Port=1521;")
    $conn.Open()
  3. Instantiate the OracleOCIDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT CompanyName, City from Customers"
    
    $da= New-Object System.Data.CData.OracleOCI.OracleOCIDataAdapter($sql, $conn)
    $dt= New-Object System.Data.DataTable
    $da.Fill($dt)
    
    $dt.Rows | foreach {
        Write-Host $_.companyname $_.city
    }

Update Oracle Data

$cmd =  New-Object System.Data.CData.OracleOCI.OracleOCICommand("UPDATE Customers SET Country='US' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.OracleOCI.OracleOCIParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()

Insert Oracle Data

$cmd =  New-Object System.Data.CData.OracleOCI.OracleOCICommand("INSERT INTO Customers (Country) VALUES (@myCountry)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.OracleOCI.OracleOCIParameter("@myCountry","US")))
$cmd.ExecuteNonQuery()

Delete Oracle Data

$cmd =  New-Object System.Data.CData.OracleOCI.OracleOCICommand("DELETE FROM Customers WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.OracleOCI.OracleOCIParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()

Ready to get started?

Download a free trial of the Oracle Data Provider to get started:

 Download Now

Learn more:

Oracle Icon Oracle ADO.NET Provider

Rapidly create and deploy powerful .NET applications that integrate with Oracle.