📄 otl4_ex241.htm
字号:
<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta content="text/html; charset=iso-8859-1"
http-equiv="Content-Type">
<meta content="Sergei Kuchin" name="Author">
<meta content="Mozilla/4.77 [en] (Win95; U) [Netscape]"
name="GENERATOR">
<meta
content="OTL, Oracle, ODBC, DB2, CLI, database API, C++, Template Library"
name="KeyWords">
<title>OTL 4.0, Example 241 (otl_datetime container with TIMESTAMP
WITH LOCAL TIME ZONE< TIMESTAMP WITH TIME ZONE, Oracle 9i))</title>
</head>
<body>
<center>
<h1>OTL 4.0, Example 241 (otl_datetime container with TIMESTAMP WITH
LOCAL TIME ZONE, TIMESTAMP WITH TIME ZONE, Oracle 9i)</h1>
</center>
This example demonstrates simple INSERT/SELECT with Oracle 9i
TIMESTAMPs [WITH [LOCAL] TIME ZONE]
and
<a href="otl3_stream_class.htm#otl_datetime">otl_datetime</a>.
<h2>Source Code</h2>
<pre>#include <iostream><br>#include <stdio.h><br>using namespace std;<br><br>#define OTL_ORA9I // Compile OTL 4.0/OCI9i<br><pre>#define <a
href="otl3_compile.htm#OTL_ORA_TIMESTAMP">OTL_ORA_TIMESTAMP</a> // enable Oracle 9i TIMESTAMPs [with [local] time zone]<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>void insert(void)<br>// insert rows into table<br>{ <br> <a
href="otl3_stream_class.htm">otl_stream</a> o(3, // stream buffer size in logical rows.<br> "insert into test_tab "<br> "values(:f1<int>,:f2<<a
href="otl3_bind_variables.htm#ltz_timestamp">ltz_timestamp</a>>,:f3<<a
href="otl3_bind_variables.htm#ltz_timestamp">tz_timestamp</a>>,:f4<<a
href="otl3_bind_variables.htm#timestamp">timestamp</a>>)", <br> // INSERT statement<br> db // connect object<br> );<br><br> <a
href="otl3_stream_class.htm#otl_datetime">otl_datetime</a> f2, f3, f4;<br><br> for(int i=1;i<=10;++i){<br>// populating a timestamp with local time zone<br> f2.year=1998;<br> f2.month=10;<br> f2.day=19;<br> f2.hour=23;<br> f2.minute=12;<br> f2.second=12;<br> f2.frac_precision=6; // microseconds<br> f2.fraction=123456;<br>// populating a timestamp with time zone<br> f3=f2;<br> f3.tz_hour=-9;<br> f3.tz_minute=0;<br>// populating a simple timestamp<br> f4=f2;<br> o<<i;<br> o<<f2;<br> o<<f3;<br> o<<f4;<br> }<br>}<br><br>void select(void)<br>{ <br> otl_stream i(5, // stream buffer size in logical rows<br> "select * from test_tab "<br> "where f1=:f1<int> "<br> " and f3=:f3<tz_tmestamp>",<br> // SELECT statement<br> db // connect object<br> ); <br>// input parameters for the SELECT statement<br> otl_datetime in_f3;<br><br>// SELECT output columns<br> int f1;<br> otl_datetime f2, f3, f4;<br><br>// setting second fraction precision to 6, microseconds<br> f2.frac_precision=6;<br> f3.frac_precision=6;<br> f4.frac_precision=6;<br><br>// populating input "timestamp with time zone"<br> in_f3.year=1998;<br> in_f3.month=10;<br> in_f3.day=19;<br> in_f3.hour=23;<br> in_f3.minute=12;<br> in_f3.second=12;<br> in_f3.frac_precision=6; // microseconds<br> in_f3.fraction=123456;<br> in_f3.tz_hour=-9;<br> in_f3.tz_minute=0;<br><br>// writing input parameters to the stream<br> i<<5<<in_f3;<br><br> while(!i.eof()){ // while not end-of-data<br> i>>f1>>f2>>f3>>f4;<br> cout<<"f1="<<f1<<endl;<br> cout<<"f2="<<f2.month<<"/"<<f2.day<<"/"<br> <<f2.year<<" "<<f2.hour<<":"<<f2.minute<<":"<br> <<f2.second<<"."<br> <<f2.fraction<<" "<br> <<f2.tz_hour<<":"<br> <<f2.tz_minute<br> <<endl;<br> cout<<"f3="<<f3.month<<"/"<<f3.day<<"/"<br> <<f3.year<<" "<<f3.hour<<":"<<f3.minute<<":"<br> <<f3.second<<"."<br> <<f3.fraction<<" "<br> <<f3.tz_hour<<":"<br> <<f3.tz_minute<br> <<endl;<br> cout<<"f4="<<f4.month<<"/"<<f4.day<<"/"<br> <<f4.year<<" "<<f4.hour<<":"<<f4.minute<<":"<br> <<f4.second<<"."<br> <<f4.fraction<br> <<endl;<br> }<br> <br>}</pre>
<pre>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 "<br> "(f1 int, "<br> " f2 timestamp with local time zone, "<br> " f3 timestamp with time zone, "<br> " f4 timestamp)"<br> ); // create table<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>& 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.sqlstate<<endl; // print out SQLSTATE message<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>}</pre>
<h2>
Output</h2>
<pre>f1=5<br>f2=10/19/1998 23:12:12.123456 -5:0<br>f3=10/19/1998 14:12:12.123456 -9:0<br>f4=10/19/1998 23:12:12.123456<br><br><br><hr
width="100%"></pre>
<center><a href="otl3_examples.htm">Examples</a> <a href="otl3.htm">Contents</a><a
href="home.htm">Go<br>Home</a></center>
<p>Copyright © 1996, 2008, Sergei Kuchin, email: <a
href="mailto:skuchin@aceweb.com">skuchin@aceweb.com</a>,<br><a
href="mailto:skuchin@gmail.com">skuchin@gmail.com<bgmailript
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></a>.<br></p>
<p><i>Permission to use, copy, modify and redistribute this document<br>for<br>any purpose is hereby granted without fee, provided that the above<br>copyright<br>notice appear in all copies.</i>
</p>
</pre>
<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 + -