📄 otl3_ex03.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 <iostream>using namespace std;#include <stdio.h></PRE><PRE>#define OTL_ORA7 // Compile OTL 4.0/OCI7#include <otlv4.h> // 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 "begin " " :A<int,inout> := :A+1; " " :B<char[31],out> := :C<char[31],in>; " "end;", // 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<<1<<"Test String1"; // assigning :A = 1, :C = "Test String1" o<<2<<"Test String2"; // assigning :A = 2, :C = "Test String2" o<<3<<"Test String3"; // assigning :A = 3, :C = "Test String3" 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>>a>>b; cout<<"A="<<a<<", B="<<b<<endl; }}int main(){ <A HREF="otl3_connect_class.htm">otl_connect::otl_initialize</A>(); // initialize OCI environment try{ db.rlogon("scott/tiger"); // connect to Oracle plsql(); } catch(<A HREF="otl3_exception_class.htm">otl_exception</A>& p){ // intercept OTL exceptions cerr<<p.msg<<endl; // print out error message cerr<<p.stm_text<<endl; // print out SQL that caused the error cerr<<p.var_info<<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 © 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 + -