Oracle temporary table C # Application

Source: Internet
Author: User
// Create global temporary table temp_20061030 (ID int, name varchar2 (256) on commit Delete rows;
Export ledboperation DBO = NULL; // export ledboperation is a custom class encapsulated for Oracle operations. You can use the operation classes and methods that come with Oracle. Here is just a description of the processing method.
Oracletransaction trans = NULL; // key first step
Try
{
DBO = new oracledboperation (); // instantiate and connect to the database

trans = DBO. connection. begintransaction (); // Key Step 2
/* -- start normal business processing using temporary tables -- */
string SQL = "insert into temp_20061030 (ID, name) Select T. ID, T. name from Table1 t where T. ID <1000 ";
DBO. executestatement (SQL);
SQL = "select max (ID) ID, count (*) CNT from temp_20061030";
datatable dt = DBO. gettable (SQL);
If (DT. rows. count> 0)
{< br> string id = DT. rows [0] ["ID"]. tostring ();
string CNT = DT. rows [0] ["CNT"]. tostring ();
MessageBox. show (ID + "/" + CNT);
}< br> else {
throw new exception ("no data ");
}< br>/* -- business processing normally using temporary tables ends -- */

trans. commit (); // Key Step 3
}< br> catch (exception ex)
{< br>/* -- release is also important -- */
If (trans! = NULL) {
trans. rollback ();
}< br> MessageBox. show (ex. message);
}< br> finally {
/* -- release is also important -- */
If (trans! = NULL) {
Trans. Dispose ();
trans = NULL;
}< br> If (DBO! = NULL) {
DBO. close ();
DBO. dispose ();
DBO = NULL;
}< BR >}< br> when the temporary table is valid within the transaction, both commit and rollback will clear the temporary table.

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.