Asp.net executes multiple oralce statements at a time.

Source: Internet
Author: User
Tags oracleconnection

 


Asp.net needs to execute multiple statements at a time, mainly by combining multiple SQL statements into statements that can be executed by Oracle.

 

Combination method can refer to Web site: http://www.cnblogs.com/scottckt/archive/2009/03/30/1425300.html

The statement to be executed can be a delete statement, a upadate statement, or an insert statement, but not a query statement.

ExampleCode:

  String Ssql =   " Delete from hp_satisfactionitem where sfiid = '{0 }'; " ;
Ssql =   String . Format (ssql, "ID ");
String Ssubsql =   " Delete from hp_satisfactionresult where sfrid = '{0 }'; " ;
Ssubsql =   String . Format (ssubsql, "ID ");

Stringbuilder sbbuilder =   New Stringbuilder ();
Sbbuilder. append ( " Begin " ). Append ( " \ N " );
Sbbuilder. append (ssql). append ( " \ N " );
Sbbuilder. append (ssubsql). append ( " \ N " );
Sbbuilder. append ( " End; " );

//Execute multiple statements
Executenonsql (sbbuilder. tostring ());

 

Executenonsql method code:

  ///   <Summary>
/// Execution statement
///   </Summary>
///   <Param name = "ssqlstring"> </param>
///   <Returns> </returns>
Public   Static   Int Executenonsql ( String Ssqlstring)
{
Int Iretruncount =   0 ;
Try
{
Sconnectionstring = Configurationmanager. configurettings. Get ( " Userconnection " );
Oracleconnection occonnection =   New Oracleconnection (sconnectionstring );
Oraclecommand occommand = Occonnection. createcommand ();
// The command type is stored procedure.
Occommand. commandtype = Commandtype. text;
Occommand. commandtext = Ssqlstring;
Occonnection. open ();
Iretruncount = Occommand. executenonquery ();
Occommand. Dispose ();
Occonnection. Close ();

}
Catch(Exception ex)
{
ThrowEx;
}

ReturnIretruncount;
}

 

 

Note:

In this example, the update statement cannot be placed in multiple rows. For example:

Ssql = @" Update Hp_satisfactionitem Set Sfititle = ' Test ' , Sfistyle = 0 , Sfiisdescription = ' 1 ' ,
Sfidescriptiontitle = ' Test ' , Sfiorder = 1 , Sfideptid = ' D024 ' , Sfinote = ' 11 '   Where Sfiid = ' D6857915-d3ae-4d7f-b908-876d80bce909 ' ;
Update Hp_satisfactionresult Set Sfrvaluetype = 1 , Sfritemlength = 10 , Sfritemone = ' 11 ' , Sfritemtwo = ' 22 ' ,
Sfritemthree = ' 33 ' , Sfritemfour = ' 44 ' , Sfritemfive = ' 55 ' , Sfritemsix = ' 66 ' , Sfritemseven = ' 77 ' , Sfritemeight = ' 88 ' , Sfritemnine = ' 99 ' , Sfritemten = ' 110 '   Where Sfrid = ' D6857915-d3ae-4d7f-b908-876d80bce909 ' ;";

In this way, the following error is reported during running.

PLS-00103: the sign "" appears when one of the following is required:
Begin case declare end
Exception exit for goto if loop mod null Pragma raise return
Select update while with <an identifier>
<A double-quoted delimited-identifier> <A Bind Variable> <
Close current Delete fetch lock insert open rollback
Savepoint set SQL execute commit forall merge
<A single-quoted SQL string> Pipe

 

 

 

 

 

Related Article

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.