📄 otl3_ex52.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>Example 52 (PL/SQL table of DATEs as parameter, Oracle 8)</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 52 (PL/SQL table of DATEs as parameter,
Oracle 8)</H1>
<H1>Example 52 (PL/SQL table of DATEs as parameter, Oracle 8)</H1>
<P>This example demonstrates how to use OTL <A HREF="otl3_pl_tab.htm">template
PL/SQL table containers</A> for reading/writing PL/SQL tables of DATEs
from/to the otl_stream.</P>
<H2>Source Code</H2>
<PRE>#include <iostream>
using namespace std;
#include <stdio.h></PRE>
<PRE>#define OTL_ORA8 // Compile OTL 4.0/OCI8
#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)
{
otl_stream s(1, // buffer size needs to be set to 1 in this case
"begin "
" pkg_test.prc_test(:v<int,in>, :t2<timestamp,out[200]>); "
"end;",
db // connect object
);
s.set_commit(0); // Since there is no transactions, unset the stream auto-commit
<A HREF="otl3_pl_tab.htm">otl_datetime_tab</A><200> t2; // PL/SQL table of otl_datetime[200]</PRE>
<PRE> s<<7; // assign :v = 7
s>>t2; // read :t2 from the stream.</PRE>
<PRE> cout<<endl<<endl<<"T2_Len="<<t2.len()<<endl;
for(int j=0;j<t2.len();++j)
if(t2.is_null(j))
cout<<"T2["<<j<<"]=NULL"<<endl;
else
cout<<"T2["<<j<<"]="<<t2.v[j].month
<<"/"<<t2.v[j].day
<<"/"<<t2.v[j].year
<<" "<<t2.v[j].hour
<<":"<<t2.v[j].minute
<<":"<<t2.v[j].second
<<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
otl_cursor::direct_exec
(db,
"CREATE OR REPLACE PACKAGE pkg_test IS "
" TYPE my_date_table IS TABLE OF DATE INDEX BY BINARY_INTEGER; "
" "
" PROCEDURE prc_test(v IN NUMBER, v2 OUT my_date_table); "
" "
"END; "
);
otl_cursor::direct_exec
(db,
"CREATE OR REPLACE PACKAGE BODY pkg_test IS "
" "
" PROCEDURE prc_test(v IN NUMBER, v2 OUT my_date_table) "
" IS "
" BEGIN "
" FOR i IN 1..v LOOP "
" v2(i) := SYSDATE-i; "
" END LOOP; "
" END; "
" "
"END; "
);
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>T2_Len=7
T2[0]=2/29/2000 15:40:33
T2[1]=2/28/2000 15:40:33
T2[2]=2/27/2000 15:40:33
T2[3]=2/26/2000 15:40:33
T2[4]=2/25/2000 15:40:33
T2[5]=2/24/2000 15:40:33
T2[6]=2/23/2000 15:40:33
<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 oldgmailsers
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 + -