(Original) ODP. Net demonstrate how to obtain oracleclob data through the parameters of the stored procedure

Source: Internet
Author: User
Tags oracleconnection
Using System;
Using System. Data;
Using System. text;
Using Oracle. dataaccess. client;
Using Oracle. dataaccess. types;

Namespace Sample33
{
// Demonstrate how to obtain oracleclob data through parameters of the stored procedure
Class Program
{
Static   Void Main ( String [] ARGs)
{
// Connect
String Constr =   " User ID = Scott; Password = tiger; Data Source = bjoracle " ;
Oracleconnection Conn = Connect (constr );

//Setup
Setup (conn );

// Set the command
Oraclecommand cmd =   New Oraclecommand ( "" , Conn );
Cmd. commandtext =   " Selectstory " ;
Cmd. commandtype = Commandtype. storedprocedure;

// bind the Oracle clob object
oracleparameter Param = cmd. parameters. add ( " clobdata " , oracledbtype. clob);
param. direction = parameterdirection. output;

// Execute Command
try
{< br> cmd. executenonquery ();

//Obtain lob data as a. Net Type
StringLob_data=(String) (Oracleclob) (CMD. Parameters [0]. Value). value;

// Print out the text
Console. writeline ( " Data is: "   + Lob_data );
}
Catch (Exception ex)
{
Console. writeline ( " Error: {0} " , Ex. Message );
}
Finally
{
// Dispose oraclecommand object
Cmd. Dispose ();

//Close and dispose oracleconnection object
Conn. Close ();
Conn. Dispose ();
}

//Waiting
Console. Readline ();
}

// Opening a new connection
Public   Static Oracleconnection connect ( String Connectstr)
{
Oracleconnection Conn =   New Oracleconnection (connectstr );
Try
{
Conn. open ();
}
Catch (Exception ex)
{
Console. writeline ( " Error: {0} " , Ex. Message );
}

ReturnConn;
}

// Setup the necessary tables & Test Data
Public   Static   Void Setup (oracleconnection conn)
{
Stringbuilder BLR;
Oraclecommand cmd =   New Oraclecommand ( "" , Conn );

BLR =   New Stringbuilder ();
BLR. append ( " Drop table multimedia_tab " );
Cmd. commandtext = BLR. tostring ();
Try
{
Cmd. executenonquery ();
}
Catch (Exception ex)
{
Console. writeline ( " Warning: {0} " , Ex. Message );
}

BLR =   New Stringbuilder ();
BLR. append ( " Create Table multimedia_tab (thekey number (4) primary key, " );
BLR. append ( " Story clob, sound BLOB) " );
Cmd. commandtext = BLR. tostring ();
Try
{
Cmd. executenonquery ();
}
Catch (Exception ex)
{
Console. writeline ( " Error: {0} " , Ex. Message );
}

BLR =   New Stringbuilder ();
BLR. append ( " Insert into multimedia_tab values ( " );
BLR. append ( " 1, " );
BLR. append ( " 'This is a long story. Once upon a time .', " );
BLR. append ( " '123 ') " );
Cmd. commandtext = BLR. tostring ();
Try
{
Cmd. executenonquery ();
}
Catch (Exception ex)
{
Console. writeline ( " Error: {0} " , Ex. Message );
}

// Build a SQL that creates Stored Procedure
Stringbuilder SQL =   New Stringbuilder ();
SQL. append ( " Create or replace procedure selectstory ( " );
SQL. append ( " Clob_data out clob) " );
SQL. append ( " Begin " );
SQL. append ( " Select story into clob_data from multimedia_tab where thekey = 1; " );
SQL. append ( " End selectstory; " );
Cmd. commandtext = SQL. tostring ();
Try
{
Cmd. executenonquery ();
}
Catch (Exception ex)
{
Console. writeline ( " Error: {0} " , Ex. Message );
}
}
}
}

Reference: ODP. Net sample

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.