Skip to Main Content

ODP.NET

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Using bind variables in Managed Provider from Powershell

Niels JespersenOct 17 2016 — edited Oct 18 2016

Hello all

In general, I find that Oracle Managed Provider works fine with Powershell. However I have trouble getting binds-vaiables to work. My example is an update. Any hints regarding what I do wrong (example below) is very welcome.

The workflow column is of datatype number in the table. The script runs fine and says that it has changed 1 row. The database column changes to null, no matter what I specify in the bind-variable.

Whether I specify [System.Data.DbType]::Int64 or [System.Data.DbType]::Decimal as bind-type changes nothing.

What do I do wrong?

Add-Type -Path "C:\Oracle12\Oracle12102x64\ODP.NET\managed\common\Oracle.ManagedDataAccess.dll"

try {

    $con = New-Object Oracle.ManagedDataAccess.Client.OracleConnection("User Id=/;Data Source=db_dst")

    $con.open()

    $cmd=$con.CreateCommand()

    $cmd.CommandText = "update workflow_tasks_t2 wt set wt.workflow_status = :sysid where wt.sys_id = 1"

    $sysid = New-Object Oracle.ManagedDataAccess.Client.OracleParameter

    $sysid.Direction = [System.Data.ParameterDirection]::Output

    $sysid.DbType =  [System.Data.DbType]::Int64

    $sysid.Value = [Int64]1

    $cmd.Parameters.Add($sysid) | Out-Null

    $rows_changed = $cmd.ExecuteNonQuery()

    Write-Host "Rows changed:" $rows_changed

}

catch

{

    Write-Error ("Error : {0}`n{1}" -f  $con.ConnectionString, $_.Exception.ToString())

}

finally

{

    if ($con.State -eq 'Open') { $con.close() }

}

This post has been answered by Mark Williams on Oct 17 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 15 2016
Added on Oct 17 2016
2 comments
1,298 views