⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 otl4_ex678.htm

📁 ISO_C++:C++_OTL开发文档
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
  <title>OTL 4.0, Example 678 (XMLType values &gt; 4000 bytes as
CLOB/std:string on SELECT, and on INSERT)</title>
  <meta name="Author" content="Sergei Kuchin">
  <meta name="GENERATOR"
 content="Mozilla/3.03Gold (Win95; I) [Netscape]">
  <meta name="KeyWords"
 content="OTL, Oracle, ODBC, DB2, CLI, database API, C++, Template Library">
</head>
<body>
<h1 align="center">OTL 4.0, Example 678 (XMLType values &gt; 4000 bytes
as CLOB/std::string on
SELECT and on INSERT)</h1>
<p>This example demonstrates simple INSERT and SELECT statements with
the large XMLType data type values (&gt;400 bytes) as well as constant
SQL statements. <br>
</p>
<h2>Source Code</h2>
<pre>#include &lt;iostream&gt;<br>#include &lt;string&gt;<br>using namespace std;<br><br>#include &lt;stdio.h&gt;<br>#define OTL_STL<br>#define OTL_ORA9I // Compile OTL 4.0/OCI9I<br>//#define OTL_ORA10G // Compile OTL 4.0/OCI10g<br>//#define OTL_ORA10G_R2 // Compile OTL 4.0/OCI10gR2<br>//#define OTL_ORA11G // Compile OTL 4.0/OCI11G<br>#include &lt;otlv4.h&gt; // include the OTL 4.0 header file<br><br><a
 href="otl3_connect_class.htm">otl_connect</a> db; // connect object<br><br>void insert()<br>// insert rows into table<br>{ <br> db.<a
 href="otl3_connect_class.htm#set_max_long_size">set_max_long_size</a>(20000); // set maximum long string size for connect object<br> <a
 href="otl3_stream_class.htm">otl_stream</a> o1(1, // buffer size needs to be set to 1<br>              "insert into temp_clob values(empty_clob()) "<br>	      "returning temp_clob into :temp_clob&lt;clob&gt;",<br>                 // SQL statement<br>              db // connect object<br>             );<br> o1.set_commit(0); // set stream's auto-commit to OFF<br> otl_stream o2(1, // buffer size needs to be set to 1<br>               "insert into test_tab "<br>	       "select :f1&lt;int&gt;, XMLType(temp_clob) from temp_clob",<br>               // SQL statement<br>               db // connect object<br>              );<br> o2.set_commit(0); // set stream's auto-commit to OFF<br> string f2_str;<br> f2_str="&lt;TAG&gt;";<br> string tmp_str;<br> tmp_str.append(6000,'.');<br> f2_str+=tmp_str;<br> f2_str+="&lt;/TAG&gt;";<br> // insert the large XML into a temporary CLOB in a temporary table.<br> o1&lt;&lt;f2_str;<br> for(int i=1;i&lt;=2;++i)<br>  o2&lt;&lt;i;<br> db.commit(); // commit transaction<br><br>}<br><br>void select()<br>{ <br> string f2;<br> db.<a
 href="otl3_connect_class.htm#set_max_long_size">set_max_long_size</a>(20000); // set maximum long string size for connect object<br><br> <a
 href="otl3_stream_class.htm">otl_stream</a> i(10, // buffer size. To read XML as CLOBs, it can be set to a size greater than 1<br>              "select f1, xmltype.getclobval(f2) f2 "<br>              "from test_tab ",<br>                 // SELECT statement<br>              db // connect object<br>             ); <br>   // create select stream<br> <br> int f1;<br><br> while(!i.eof()){ // while not end-of-data<br>  i&gt;&gt;f1&gt;&gt;f2;<br>  cout&lt;&lt;"f1="&lt;&lt;f1&lt;&lt;", f2="&lt;&lt;f2&lt;&lt;endl;<br> }<br><br>}<br><br>int main()<br>{<br> <a
 href="otl3_connect_class.htm">otl_connect::otl_initialize</a>(); // initialize OCI environment<br> try{<br><br>  db.rlogon("scott/tiger"); // connect to Oracle<br><br>  <a
 href="otl3_const_sql.htm">otl_cursor::direct_exec<br></a>   (<br>    db,<br>    "drop table test_tab",<br>    otl_exception::disabled // disable OTL exceptions<br>   ); // drop table<br><br>  <a
 href="otl3_const_sql.htm">otl_cursor::direct_exec<br></a>   (<br>    db,<br>    "create table test_tab(f1 number, f2 xmltype)"<br>    );  // create table<br><br>// create global temporary table for temporary CLOB values<br>  db.direct_exec("drop table temp_clob",<br>                 otl_exception::disabled);<br>  db.direct_exec("create global temporary table temp_clob(temp_clob clob) "<br>                 "ON COMMIT delete rows");<br><br><br>  insert(); // insert records into table<br>  select(); // select records from table<br><br> }<br><br> catch(<a
 href="otl3_exception_class.htm">otl_exception</a>&amp; p){ // intercept OTL exceptions<br>  cerr&lt;&lt;p.msg&lt;&lt;endl; // print out error message<br>  cerr&lt;&lt;p.stm_text&lt;&lt;endl; // print out SQL that caused the error<br>  cerr&lt;&lt;p.var_info&lt;&lt;endl; // print out the variable that caused the error<br> }<br><br> db.logoff(); // disconnect from Oracle<br><br> return 0;<br><br>}<br></pre>
<h2>Output</h2>
<pre>f1=1, f2=&lt;TAG&gt;................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................&lt;/TAG&gt;<br>f1=2, f2=&lt;TAG&gt;................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................&lt;/TAG&gt;<br><br><hr

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -