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

📄 otl3_ex03.htm

📁 otl是c++数据库封装好的一个数据库接口
💻 HTM
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"><HTML><HEAD>   <TITLE>OTL 4.0, Example 3 (PL/SQL block)</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 3 (PL/SQL block)</H1><H1><A NAME="example1"></A>Example 3 (PL/SQL block)</H1><P>This example demonstrates a anonymous PL/SQL block with input and outputvariables.</P><H2>Source Code</H2><PRE>#include &lt;iostream&gt;using namespace std;#include &lt;stdio.h&gt;</PRE><PRE>#define OTL_ORA7 // Compile OTL 4.0/OCI7#include &lt;otlv4.h&gt; // include the OTL 4.0 header file<A HREF="otl3_connect_class.htm">otl_connect</A> db; // connect object</PRE><PRE>void plsql(void)// invoking PL/SQL block{  <A HREF="otl3_stream_class.htm">otl_stream</A> o(5, // buffer size              &quot;begin &quot;              &quot; :A&lt;int,inout&gt; := :A+1; &quot;              &quot; :B&lt;char[31],out&gt; := :C&lt;char[31],in&gt;; &quot;              &quot;end;&quot;,                 // PL/SQL block              db // connect object             );</PRE><PRE> o.<A HREF="otl3_stream_class.htm#set_commit">set_commit</A>(0); // set stream auto-commit off since                   // the block does not have any transactions                  // to commit</PRE><PRE> o&lt;&lt;1&lt;&lt;&quot;Test String1&quot;; // assigning :A = 1, :C = &quot;Test String1&quot; o&lt;&lt;2&lt;&lt;&quot;Test String2&quot;; // assigning :A = 2, :C = &quot;Test String2&quot; o&lt;&lt;3&lt;&lt;&quot;Test String3&quot;; // assigning :A = 3, :C = &quot;Test String3&quot; o.<A HREF="otl3_stream_class.htm#flush">flush</A>(); // executing PL/SQL block 3 times int a; char b[32]; while(!o.eof()){ // not end-of-data  o&gt;&gt;a&gt;&gt;b;  cout&lt;&lt;&quot;A=&quot;&lt;&lt;a&lt;&lt;&quot;, B=&quot;&lt;&lt;b&lt;&lt;endl; }}int main(){ <A HREF="otl3_connect_class.htm">otl_connect::otl_initialize</A>(); // initialize OCI environment try{  db.rlogon(&quot;scott/tiger&quot;); // connect to Oracle  plsql(); } catch(<A HREF="otl3_exception_class.htm">otl_exception</A>&amp; p){ // intercept OTL exceptions  cerr&lt;&lt;p.msg&lt;&lt;endl; // print out error message  cerr&lt;&lt;p.stm_text&lt;&lt;endl; // print out SQL that caused the error  cerr&lt;&lt;p.var_info&lt;&lt;endl; // print out the variable that caused the error } db.logoff(); // disconnect from Oracle return 0;}</PRE><H2>Output</H2><PRE>A=2, B=Test String1A=3, B=Test String2A=4, B=Test String3<HR WIDTH="100%"></PRE><CENTER><P><A HREF="otl3_examples.htm">Examples</A> <A HREF="otl3.htm">Contents</A><A HREF="home.htm">Go Home</A> </P></CENTER><P>Copyright &copy; 1996, 2008, Sergei Kuchin, email: <A HREF="mailto:skuchin@aceweb.com">skuchin@aceweb.com</A>,<A HREF="mailto:skuchin@gmail.com">skuchin@gmail.com/A>.<SCRIPT Language="JavaScript"><!-- hide from old browsers var modDate = new Date(document.lastModified) document.write("<i> Last Updated:</i> " + (modDate.getMonth()+1) + "/" +                 modDate.getDate() + "/" + "0"+(modDate.getYear())%100+"."); //--> </SCRIPT></P><P><I>Permission to use, copy, modify and redistribute this document forany purpose is hereby granted without fee, provided that the above copyrightnotice appear in all copies. </I></P></BODY></HTML>

⌨️ 快捷键说明

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