Created
May 15, 2012 14:10
-
-
Save gsherman/2702060 to your computer and use it in GitHub Desktop.
a simple powershell script for calling an oracle stored procedure with both input and output parameters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$asm = [System.Reflection.Assembly]::LoadWithPartialName("System.Data.OracleClient") | |
$connectionString = "Data Source=myDatabase;uid=sa;pwd=sa"; | |
$inputString = "foo"; | |
$oracleConnection = new-object System.Data.OracleClient.OracleConnection($connectionString); | |
$cmd = new-object System.Data.OracleClient.OracleCommand; | |
$cmd.Connection = $oracleConnection; | |
$cmd.CommandText = "isFoo"; | |
$cmd.CommandType = [System.Data.CommandType]::StoredProcedure; | |
$cmd.Parameters.Add("inputString", [System.Data.OracleClient.OracleType]::VarChar) | out-null; | |
$cmd.Parameters["inputString"].Direction = [System.Data.ParameterDirection]::Input; | |
$cmd.Parameters["inputString"].Value = $inputString; | |
$cmd.Parameters.Add("outNumber", [System.Data.OracleClient.OracleType]::Number) | out-null; | |
$cmd.Parameters["outNumber"].Direction = [System.Data.ParameterDirection]::Output; | |
$oracleConnection.Open(); | |
$cmd.ExecuteNonQuery() | out-null; | |
$oracleConnection.Close(); | |
$result = $cmd.Parameters["outNumber"].Value; | |
write-host "result of isFoo($inputString) is $result" -foregroundcolor yellow; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this... I had the same issue :)
I also had to add:
$cmd.Parameters["outText"].size = 5000;
As I changed the out number to a varchar...