📄 otl4_ex312.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>Example 312 (Large PL/SQL tables as parameters)</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 312 (Large PL/SQL tables as
parameters)</h1>
<p>This example demonstrates how to use OTL <a href="otl3_pl_tab.htm">template
& dymanic PL/SQL table containers</a> for reading/writing PL/SQL
tables
from/to the otl_stream.</p>
<h2>Source Code</h2>
<pre>#include <iostream><br>using namespace std;<br><br>#include <stdio.h></pre>
<pre>//#define OTL_ORA8 // Compile OTL 4.0/OCI8<br>#define OTL_ORA8I // Compile OTL 4.0/OCI8i<br>//#define OTL_ORA9I // Compile OTL 4.0/OCI9i<br>//#define OTL_ORA10G // Compile OTL 4.0/OCI10g<br>#include <otlv4.h> // include the OTL 4.0 header file<br><br><a
href="otl3_connect_class.htm">otl_connect</a> db; // connect object<br><br> <a
href="otl3_pl_tab.htm">otl_int_tab<</a>50000> t1; // PL/SQL table of int[50000]<br></pre>
<pre>void plsql(void)<br>{ <br> otl_stream s(1, // buffer size needs to be set to 1 in this case<br> "begin "<br> " pkg_test.prc_test(:tsize<int,in>,:t1<int,out[50000]>); "<br> "end;",<br> db // connect object<br> );<br><br> s.set_commit(0); // Since there is no transactions, unset the stream auto-commit<br></pre>
<span style="font-family: monospace;"> s<<50000; // write
:tsize into the stream, since it is input</span><br>
<span style="font-family: monospace;">s>>t1; // read :t1
from the stream since it is output</span><br>
<pre> cout<<"T1_Len="<<t1.len()<<endl;<br> if(t1.is_null(0))<br> cout<<"T1["<<0<<"]=NULL"<<endl;<br> else<br> cout<<"T1["<<0<<"]="<<t1.v[0]<<endl;<br> if(t1.is_null(t1.len()-1))<br> cout<<"T1["<<t1.len()-1<<"]=NULL"<<endl;<br> else<br> cout<<"T1["<<t1.len()-1<<"]="<<t1.v[t1.len()-1]<<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> otl_cursor::direct_exec<br> (db,<br> "CREATE OR REPLACE PACKAGE pkg_test IS "<br> " TYPE my_numeric_table IS TABLE OF NUMBER INDEX BY BINARY_INTEGER; "<br> " PROCEDURE prc_test(tsize IN NUMBER, v1 OUT my_numeric_table); "<br> " "<br> "END; "<br> );<br><br> otl_cursor::direct_exec<br> (db,<br> "CREATE OR REPLACE PACKAGE BODY pkg_test IS "<br> " "<br> " PROCEDURE prc_test(tsize IN NUMBER, v1 OUT my_numeric_table) "<br> " IS "<br> " BEGIN "<br> " FOR i IN 1..tsize LOOP "<br> " v1(i) := i; "<br> " END LOOP; "<br> " END; "<br> " "<br> "END; "<br> );<br><br><br> plsql();<br><br> }<br><br> catch(<a
href="otl3_exception_class.htm">otl_exception</a>& p){ // intercept OTL exceptions<br> cerr<<p.msg<<endl; // print out error message<br> cerr<<p.stm_text<<endl; // print out SQL that caused the error<br> cerr<<p.var_info<<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>T1_Len=50000<br>T1[0]=1<br>T1[49999]=50000<br><br><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@yahogmail</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
for
any purpose is hereby granted without fee, provided that the above
copyright
notice appear in all copies. </i></p>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-5456201-1");
pageTracker._trackPageview();
</script>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -