oracle中testwindow打断点,閫氳繃 Visual Studio .NET 璋冭瘯 Oracle PL/SQL

该博客展示了如何使用C#通过Oracle.DataAccess.Client连接Oracle数据库,调用存储过程`OBE.determine_primes`和`oramag.add_new_job`。程序输入数组并接收输出数组以判断质数,并创建新的数据库作业。代码详细说明了参数设置和执行过程。
摘要由CSDN通过智能技术生成

澶嶅埗浠ヤ笅浠g爜骞跺皢鍏剁矘璐村埌 Visual Studio 鐨� Program.cs 绐楀彛涓�傚彸閿崟鍑� Program.cs 閫夐」鍗★紝閫夋嫨 Save Program.cs銆�

using System;

using System.Data;

using Oracle.DataAccess.Client;

using Oracle.DataAccess.Types;

namespace plsqldebugobe1

{

///

/// Summary description for Class1.

///

class Program

{

///

/// The main entry point for the application.

///

[STAThread]

static void Main(string[] args)

{

// constants used to represent values returned

// from the pl/sql procedure call

const int IS_NOT_A_PRIME = 0;

const int IS_A_PRIME = 1;

// display progress message

Console.WriteLine("Testing array for prime numbers...\n");

// connection string: adjust for your environment

string constr = "User Id=hr; Password=hr; Data Source=ORCL; enlist=false; pooling=false";

// create and open connection object

OracleConnection con = new OracleConnection(constr);

con.Open();

// create command object for the function call

OracleCommand cmd = new OracleCommand();

cmd.Connection = con;

cmd.CommandText = "OBE.determine_primes";

// set the proper command type

cmd.CommandType = CommandType.StoredProcedure;

// parameter object for the input array

OracleParameter p_in_values = new OracleParameter();

p_in_values.OracleDbType = OracleDbType.Decimal;

p_in_values.CollectionType = OracleCollectionType.PLSQLAssociativeArray;

p_in_values.Value = new decimal[10]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

p_in_values.Size = 10;

p_in_values.Direction = ParameterDirection.Input;

// parameter object for the output array

OracleParameter p_out_values = new OracleParameter();

p_out_values.OracleDbType = OracleDbType.Decimal;

p_out_values.CollectionType = OracleCollectionType.PLSQLAssociativeArray;

p_out_values.Value = null;

p_out_values.Size = 10;

p_out_values.Direction = ParameterDirection.Output;

// add parameters to the collection

// they must be added in the proper

// order when using bind by position (the default)

cmd.Parameters.Add(p_in_values);

cmd.Parameters.Add(p_out_values);

// execute the pl/sql procedure to populate output array

cmd.ExecuteNonQuery();

// display results to console window

for (int i = 0; i < p_in_values.Size; i++)

{

foreach (OracleParameter p in cmd.Parameters)

{

// the input array is treated as System.Decimal[]

// within the .NET code

if (p.Value is System.Decimal[])

{

Console.Write("The Number {0} ", ((p.Value as System.Decimal[])[i]).ToString());

}

// the output array is treated as OracleDecimal[]

// within the .NET code

if (p.Value is OracleDecimal[])

{

if (((p.Value as OracleDecimal[])[i]).ToInt32() == IS_NOT_A_PRIME)

{

Console.WriteLine("is not a prime number!");

}

else if (((p.Value as OracleDecimal[])[i]).ToInt32() == IS_A_PRIME)

{

Console.WriteLine("is a prime number!");

}

}

}

}

// display a separator line

Console.WriteLine();

// display progress message

Console.WriteLine("Using PL/SQL record...\n");

// remove parameters from command collection

// and set new command text

cmd.Parameters.Clear();

cmd.CommandText = "oramag.add_new_job";

// parameter object for the job_id

OracleParameter p_job_id = new OracleParameter();

p_job_id.Value = "IT_DBA";

// parameter object for the job_title

OracleParameter p_job_title = new OracleParameter();

p_job_title.Value = "Database Administrator";

// parameter object for the min_salary

OracleParameter p_min_salary = new OracleParameter();

p_min_salary.OracleDbType = OracleDbType.Decimal;

p_min_salary.Value = 10000;

// parameter object for the max_salary

OracleParameter p_max_salary = new OracleParameter();

p_max_salary.OracleDbType = OracleDbType.Decimal;

p_max_salary.Value = 15000;

// add parameters to collection

cmd.Parameters.Add(p_job_id);

cmd.Parameters.Add(p_job_title);

cmd.Parameters.Add(p_min_salary);

cmd.Parameters.Add(p_max_salary);

// execute the pl/sql procedure to add new job

cmd.ExecuteNonQuery();

// display simple message to indicate procedure completed

Console.WriteLine("New job successfully created!");

// display a separator line

Console.WriteLine();

// Simple prompt to prevent the console from closing

// when running from the IDE

Console.WriteLine("Press ENTER to continue...");

Console.ReadLine();

// clean up objects

p_max_salary.Dispose();

p_min_salary.Dispose();

p_job_title.Dispose();

p_job_id.Dispose();

p_out_values.Dispose();

p_in_values.Dispose();

cmd.Dispose();

con.Dispose();

}

}

}

5b1149683ad763b262b096fa994876b6.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值