Click here to Skip to main content
15,887,746 members
Home / Discussions / Database
   

Database

 
GeneralRe: SQL int question (Probably an easy answer too) Pin
Tad McClellan12-Nov-05 4:41
professionalTad McClellan12-Nov-05 4:41 
Questionremove a datatable from a dataset Pin
webx1011-Nov-05 10:34
webx1011-Nov-05 10:34 
Questionconnection problem Pin
ashee200011-Nov-05 9:04
ashee200011-Nov-05 9:04 
AnswerRe: connection problem Pin
Colin Angus Mackay11-Nov-05 12:01
Colin Angus Mackay11-Nov-05 12:01 
GeneralRe: connection problem Pin
ashee200014-Nov-05 7:16
ashee200014-Nov-05 7:16 
AnswerRe: connection problem Pin
ricardojb14-Nov-05 17:25
ricardojb14-Nov-05 17:25 
QuestionPassing parameter to Oracle Pin
softty11-Nov-05 8:42
softty11-Nov-05 8:42 
AnswerRe: Passing parameter to Oracle Pin
anandss11-Nov-05 9:18
anandss11-Nov-05 9:18 
You need to use, ODP.Net , Data Provider for Oracle supplied by Oracle. Assuming you have that here is the example from Oracle
/********* Example Start *************/
using System;
using System.Data;
using System.Text;
using System.Reflection;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;

namespace ODPSample
{
class AssocArray
{
static void Main(string[] args)
{
Console.WriteLine("Demo: PL/SQL Associative Array");

// Connect
string connectStr = "User Id=scott;Password=tiger;Data Source=oracle";

// Setup the Tables for sample
Setup(connectStr);

OracleConnection connection = new OracleConnection(connectStr);
OracleCommand cmd = new OracleCommand("begin MyPack.TestVarchar2(:1, :2, :3);end;",
connection);

OracleParameter param1 = cmd.Parameters.Add("param1", OracleDbType.Varchar2);
OracleParameter param2 = cmd.Parameters.Add("param2", OracleDbType.Varchar2);
OracleParameter param3 = cmd.Parameters.Add("param3", OracleDbType.Varchar2);

// Setup the direction
param1.Direction = ParameterDirection.Input;
param2.Direction = ParameterDirection.InputOutput;
param3.Direction = ParameterDirection.Output;

// Specify that we are binding PL/SQL Associative Array
param1.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
param2.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
param3.CollectionType = OracleCollectionType.PLSQLAssociativeArray;

param1.Value = new string[3]{"Input1",
"Input2",
"Input3"};
param2.Value = new string[3]{"Inout1",
"Inout2",
"Inout3"};
param3.Value = null;

// Specify the maximum number of elements in the PL/SQL Associative
// Array
param1.Size = 3;
param2.Size = 3;
param3.Size = 3;

// Setup the ArrayBind Size for param1
param1.ArrayBindSize = new int[3]{13,14,13};

// Setup the ArrayBind Status for param1
param1.ArrayBindStatus = new OracleParameterStatus[3]{
OracleParameterStatus.Success,
OracleParameterStatus.Success,
OracleParameterStatus.Success};

// Setup the ArrayBind Size for param2
param2.ArrayBindSize = new int[3]{20,20,20};

// Setup the ArrayBind Size for param3
param3.ArrayBindSize = new int[3]{20,20,20};

try
{
connection.Open();
cmd.ExecuteNonQuery();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}

Console.WriteLine("Results:");
Display(cmd.Parameters);
}

public static void Setup(string connectStr)
{
OracleConnection connection = new OracleConnection(connectStr);
OracleCommand command = new OracleCommand("", connection);

try
{
connection.Open();

command.CommandText = "drop table T1";
try
{
command.ExecuteNonQuery();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}

command.CommandText = "CREATE TABLE T1(COL1 number, COL2 varchar2(20))";
command.ExecuteNonQuery();

StringBuilder hdr = new StringBuilder();
hdr.Append("CREATE or replace PACKAGE MYPACK AS ");
hdr.Append("TYPE AssocArrayVarchar2_t is table of VARCHAR(20) index by BINARY_INTEGER;");
hdr.Append(" PROCEDURE TestVarchar2(");
hdr.Append(" Param1 IN AssocArrayVarchar2_t,");
hdr.Append(" Param2 IN OUT AssocArrayVarchar2_t,");
hdr.Append(" Param3 OUT AssocArrayVarchar2_t);");
hdr.Append(" END MYPACK;");
command.CommandText = hdr.ToString();
command.ExecuteNonQuery();

StringBuilder body = new StringBuilder();
body.Append("CREATE or REPLACE package body MYPACK as ");
body.Append(" PROCEDURE TestVarchar2(");
body.Append(" Param1 IN AssocArrayVarchar2_t,");
body.Append(" Param2 IN OUT AssocArrayVarchar2_t,");
body.Append(" Param3 OUT AssocArrayVarchar2_t)");
body.Append(" IS");
body.Append(" i integer;");
body.Append(" BEGIN");
body.Append(" -- copy a few elements from Param2 to Param1\n");
body.Append(" Param3(1) := Param2(1);");
body.Append(" Param3(2) := NULL;");
body.Append(" Param3(3) := Param2(3);");
body.Append(" -- copy all elements from Param1 to Param2\n");
body.Append(" Param2(1) := Param1(1);");
body.Append(" Param2(2) := Param1(2);");
body.Append(" Param2(3) := Param1(3);");
body.Append(" -- insert some values to db\n");
body.Append(" FOR i IN 1..3 LOOP");
body.Append(" insert into T1 values(i,Param2(i));");
body.Append(" END LOOP;");
body.Append(" END TestVarchar2;");
body.Append("END MYPACK;");


command.CommandText = body.ToString();
command.ExecuteNonQuery();

command.CommandText="Commit";
command.ExecuteNonQuery();
}
catch (Exception e)
{
Console.WriteLine(command.CommandText + ":" + e.Message);
}

}

public static void Display(OracleParameterCollection collection)
{
foreach(OracleParameter p in collection)
{
Console.Write(p.ParameterName + ": ");
for(int i=0;i<3;i++)
{
if (p.Value is OracleString[])
Console.Write((p.Value as OracleString[])[i]);
else
Console.Write((p.Value as string[])[i]);
Console.Write(" ");
}
Console.WriteLine();
}
}
}
}
/********* Example End *************/



Regards
QuestionSQL SPLIT INSERT AND JOIN.... Pin
ModuleKev11-Nov-05 2:13
ModuleKev11-Nov-05 2:13 
QuestionHow to get RelationShip Between SQL Functions? Pin
pubududilena11-Nov-05 1:56
pubududilena11-Nov-05 1:56 
AnswerRe: How to get RelationShip Between SQL Functions? Pin
Colin Angus Mackay11-Nov-05 4:37
Colin Angus Mackay11-Nov-05 4:37 
Questionupdate in the same table Pin
Goodway10-Nov-05 20:18
Goodway10-Nov-05 20:18 
AnswerRe: update in the same table Pin
softty11-Nov-05 8:54
softty11-Nov-05 8:54 
GeneralRe: update in the same table Pin
anandss11-Nov-05 12:55
anandss11-Nov-05 12:55 
GeneralRe: update in the same table Pin
Goodway14-Nov-05 20:48
Goodway14-Nov-05 20:48 
QuestionInvalidated ADO Connection Object Pin
alex120510-Nov-05 19:31
alex120510-Nov-05 19:31 
AnswerRe: Invalidated ADO Connection Object Pin
S Douglas13-Nov-05 22:02
professionalS Douglas13-Nov-05 22:02 
GeneralRe: Invalidated ADO Connection Object Pin
alex120514-Nov-05 0:18
alex120514-Nov-05 0:18 
GeneralRe: Invalidated ADO Connection Object Pin
S Douglas14-Nov-05 0:46
professionalS Douglas14-Nov-05 0:46 
Questionsql problem Pin
ppp00110-Nov-05 18:33
ppp00110-Nov-05 18:33 
AnswerRe: sql problem Pin
Colin Angus Mackay11-Nov-05 0:11
Colin Angus Mackay11-Nov-05 0:11 
QuestionASP.net (c#) and SQL server Pin
Sasuko10-Nov-05 6:19
Sasuko10-Nov-05 6:19 
AnswerRe: ASP.net (c#) and SQL server Pin
Colin Angus Mackay10-Nov-05 13:50
Colin Angus Mackay10-Nov-05 13:50 
QuestionHELP...SQL Server DTS Package probs... Pin
murrayb302410-Nov-05 6:02
murrayb302410-Nov-05 6:02 
AnswerUpdate Pin
murrayb302410-Nov-05 6:42
murrayb302410-Nov-05 6:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.