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

📄 otl3_bind_variables.htm

📁 ISO_C++:C++_OTL开发文档
💻 HTM
📖 第 1 页 / 共 2 页
字号:
      <td style="vertical-align: top;"><span style="font-weight: bold;"><a
 name="refcur"></a>refcur</span><br>
      </td>
      <td style="vertical-align: top;">for Oracle 8/9/10/11. When a
stored procedure returns a reference cursor, a bind variable of <span
 style="font-style: italic;">refcur</span> type may be declared in the
PL/SQL block that calls the stored procedure, for example:<br>
      <br>
      <pre>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "begin "<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; " my_pkg.my_proc(:f1&lt;int,in&gt;,:f2&lt;int,in&gt;, "<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :str1&lt;char[100],out&gt;, "<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // :str1 is an output string parameter<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :cur1&lt;refcur,out[50]&gt;, "<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :cur2&lt;refcur,out[50]&gt;); "<br>&nbsp;&nbsp;&nbsp;&nbsp; // :cur1, :cur2 are a bind variable names, refcur -- their types,&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp; // out -- output parameter, 50 -- the buffer size when this<br>&nbsp;&nbsp;&nbsp;&nbsp; // reference cursor will be attached to <a
 href="otl4_refcur_stream.htm">otl_refcur_stream<br></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "end;"</pre>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;"><b>short</b></td>
      <td style="vertical-align: top;">short int (16-bit signed integer)<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;"><a name="timestamp"></a><b>timestamp</b></td>
      <td style="vertical-align: top;">MS SQL
Server/Sybase
DATETIME,
DB2 TIMESTAMP, Oracle DATE, Oracle 9i TIMESTAMP (when #define <a
 href="otl3_compile.htm#OTL_ORA_TIMESTAMP">OTL_ORA_TIMESTAMP</a>
is enabled) ; it&nbsp; requires TIMESTAMP_STRUCT
(OTL/ODBC, OTL/DB2-CLI), or <a
 href="otl3_stream_class.htm#otl_datetime">otl_datetime</a>
(ODBC, DB2-CLI, and OCIx).&nbsp; OTL/DB2-CLI
and OTL/ODBC for DB2; requires <a
 href="otl3_stream_class.htm#otl_datetime">otl_datetime</a>
as a data container. See example <a href="otl3_ex91.htm">91</a> for
more
detail</td>
    </tr>
    <tr>
      <td style="vertical-align: top;"><a name="tz_timestamp"></a><b>tz_timestamp</b><a
 href="otl3_stream_class.htm#otl_datetime"></a></td>
      <td style="vertical-align: top;">Oracle 9i
TIMESTAMP WITH TIME ZONE, in a combination with #define <a
 href="otl3_compile.htm#OTL_ORA_TIMESTAMP">OTL_ORA_TIMESTAMP</a>,
and <a href="otl3_stream_class.htm#otl_datetime">otl_datetime</a></td>
    </tr>
    <tr>
      <td style="vertical-align: top;"><b>unsigned</b></td>
      <td style="vertical-align: top;">unsigned int (32-bit unsigned
integer)<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;"><a name="varchar_long"></a><b>varchar_long</b></td>
      <td style="vertical-align: top;">for Oracle 7:
LONG; for
Oracle 8/9: LONG; for ODBC: SQL_LONGVARCHAR; for DB2: CLOB</td>
    </tr>
  </tbody>
</table>
<br>
<br>
varchar_long, raw_long clob and blob require the <a
 href="otl3_long_string.htm">otl_long_string</a>
class as a data container. In order to set the maximum size for
varchar_long,
raw_long, clob or blob, see the set_max_long_size() function in the <a
 href="otl3_connect_class.htm">otl_connect</a>
class for more detail.
<p><a name="access_qualifiers"></a>For PL/SQL blocks (OTL 4.0/OCI7,
OTL4.0/OCI8/9)
or stored procedure calls (OTL 4.0/ODBC, OTL 4.0/DB2-CLI), special
qualifiers
are introduced to distinguish between input and output variables:
</p>
<ul>
  <li> <b>in</b> -- input variable</li>
  <li> <b>out </b>-- output variable</li>
  <li> <b>inout </b>-- input/output variable</li>
</ul>
<b>Example 1 (Oracle):</b>
<pre>&nbsp;BEGIN<br>&nbsp;&nbsp; :rc&lt;int,out&gt; := my_func(:salary&lt;float,in&gt;,&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :ID&lt;int,inout&gt;,&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :name&lt;char[32],out&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );<br>&nbsp;END;</pre>
<b>Example 2 (ODBC or DB2-CLI):</b>
<p>New (OTL 4.0/ODBC, OTL 4.0/DB2-CLI) style
</p>
<pre>&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; call :rc&lt;int,out&gt; := my_func(:salary&lt;float,in&gt;,&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :ID&lt;int,inout&gt;,&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :name&lt;char[32],out&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br>&nbsp;&nbsp; }</pre>
<pre>Old (OTL 2.0/ODBC) style:</pre>
<pre>&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; call :1&lt;int,out&gt; := my_func(:2&lt;float,in&gt;,&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :3&lt;int,inout&gt;,&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :4&lt;char[32],out&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br>&nbsp;&nbsp; }</pre>
In the bind variable declaration, spaces in the datatype section and in
the access qualifier section ARE NOT allowed. The following code is
invalid:
<p><b>Example 1</b>
</p>
<pre>&nbsp; insert into tab1 values(:salary&lt; double &gt;, :name&lt; char [ 32 ] &gt; , :emp_id&lt; int&gt;);</pre>
<p><br>
<b>Example 2</b>
</p>
<pre>&nbsp; :rc&lt; int, out &gt; := ...;<br><br></pre>
<h3><b><font><b><font size="+2"><a name="COLON_LITERAL"></a>Embedding
colon (":") literals into SQL statements in OTL/ODBC</font></b></font></b></h3>
<p>Informix Call Level Interface (CLI) can be used in a combination
with OTL/ODBC. Informix SQL allows colons (":") as legitimate
characters in Informix SQL statements. Therefore, there is a need to
embed colon literal into such SQL statements. The following notation
can be used for embedding colons into SQL statements under OTL/ODBC: "<span
 style="font-family: monospace;">\\:</span>". OTL/ODBC 4.0.68 and
higher supports the notation.<b><font><b><font size="+2"><br>
</font></b></font></b></p>
<h3><br>
<a name="SELECT_OVERRIDE"></a><b><font><b><font size="+2">Explicit bind
variables in output column definitions in SELECT statements<br>
</font></b></font></b></h3>
<p>OTL describes output column names, datatypes, and column lengths
dynamically right after the SELECT statement is parsed. OTL maps column
internal datatypes into C++ external datatypes by default. The default
mapping can be overriden by <a
 href="otl3_stream_class.htm#set_column_type">otl_stream::set_column_type</a>()
and <a href="otl3_stream_class.htm#set_all_column_types">otl_stream::set_all_column_types</a>()
function calls. However, it is not as convenient as defining explicit
bind variables right in the text of the SQL statement.In OTL 4.0.73, a
special kind of bind variables is introduced: explicit bind variables
for defining datatypes of output columns in SELECT statements. The
format for defining explicit bind variables in SELECT statement's
columns is as follows: <span style="font-weight: bold;">:#N&lt;datatype&gt;</span>,
where N is 1,2,3 (column's relative position in the SELECT
statement)... SELECT
output columns do not have a direct equivalent of <span
 style="font-style: italic;"><span style="font-weight: bold;">:VAR</span>
</span>(OCI), or <span style="font-style: italic; font-weight: bold;">?</span>
(ODBC, DB2-CLI), so if an explicit bind variable is defined for a
column in a SELECT statement, the bind variable has to be blanked out
in the resulting format of the SELECT statement that gets passed into
the database API. For example:<br>
</p>
&nbsp;&nbsp;&nbsp; SELECT f1 <span style="font-style: italic;">:#1&lt;short&gt;</span>,
f2<br>
&nbsp;&nbsp;&nbsp; FROM test_tab<br>
&nbsp;&nbsp;&nbsp;&nbsp; ...<br>
<p>Here is the resulting SELECT statement that gets passed into the
database API:<br>
</p>
&nbsp;&nbsp;&nbsp; SELECT f1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; , f2<br>
&nbsp;&nbsp;&nbsp; FROM test_tab<br>
<br>
<p>The set of datatypes allowed in <span style="font-style: italic;">:#N&lt;datatype&gt;</span>
is limited and database API specific, In general, the following types
are allowed:<br>
</p>
<ul>
  <li>&nbsp;&lt;char[XXX]&gt;</li>
  <li>&nbsp;&lt;double&gt;</li>
  <li>&nbsp;&lt;float&gt;</li>
  <li>&nbsp;&lt;int&gt;</li>
  <li>&nbsp;&lt;bigint&gt; (which is supported natively in ODBC /
DB2-CLI, and OTL internally emulates bigints via strings (char[XXX])
for OCIs).<br>
  </li>
  <li>&nbsp;&lt;unsigned&gt;</li>
  <li>&nbsp;&lt;short&gt;</li>
  <li>&nbsp;&lt;long&gt;</li>
  <li>&lt;raw&gt;<br>
  </li>
  <li>&lt;raw_long&gt;<br>
  </li>
  <li>&lt;timestamp&gt;</li>
  <li>&lt;varchar_long&gt;<br>
  </li>
</ul>
Also, it depends on the internal type of the column to be overriden
whether the target type (from the list above) is compatible with the
source / internal type of the column or not. For more detail, refer to
the correspoding database API manual. A quick way to figure out if the
types are compatible is through trial and error.<br>
<br>
The OTL internal to external default data type mapping for output
columns in SELECT statement works okay for the most part, except for
rare cases when there may be some special considerations for
performance, or external datatype definitions (for example,
compatibility
with predefined or general-purpose C++ containers).<br>
<br>
<a name="SP_COL_OVERRIDE"></a>In OTL 4.0.117 and higher, it is possible
to do the same kind of overriding (as described above) for&nbsp; output
column datatypes of an implicit result set (ODBC/DB2-CLI), or a
reference cursor (Oracle), for example:<br>
<br>
<span style="font-style: italic;">&nbsp;&nbsp;&nbsp; Oracle:<br>
<br>
</span>&nbsp;&nbsp;&nbsp; <span style="font-family: monospace;">otl_stream
<br>
&nbsp;&nbsp;&nbsp;&nbsp; s(50,<br>
</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
"<span style="font-family: monospace;">BEGIN "<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "
my_proc1(:f1&lt;int,in&gt;,:res_set); "<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "&nbsp;&nbsp; :#1&lt;int,out&gt; "<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "&nbsp;&nbsp;
:#2&lt;char[31],out&gt; "<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; "END;",<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db, // otl_connect object<br>
</span><span style="font-style: italic;"></span>&nbsp; &nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span style="font-family: monospace;">":res_set" // reference cursor /
result set's placeholder name<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );<br>
<br>
</span><span style="font-style: italic;">&nbsp;&nbsp;&nbsp;
ODBC/DB2-CLI:<br>
<br>
</span>&nbsp;&nbsp;&nbsp; <span style="font-family: monospace;">otl_stream
<br>
&nbsp;&nbsp;&nbsp;&nbsp; s(50,<br>
</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
"<span style="font-family: monospace;">{ "<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; " my_proc1(:f1&lt;int,in&gt;) "<br>
</span><span style="font-family: monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
"&nbsp;&nbsp; :#1&lt;int,out&gt; "<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "&nbsp;&nbsp;
:#2&lt;char[31],out&gt; "<br>
</span><span style="font-family: monospace;">&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; "}",<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db, // otl_connect object<br>
</span><span style="font-style: italic;"></span>&nbsp; &nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span
 style="font-family: monospace;">otl_implicit_select // implicit result
set / select flag<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );</span><br>
<br>
Output column overrides are optional. If a column is not overriden
explicitly, the default datatype mapping applies..<br>
<h3><a name="pl_tab"></a><b><font size="+2">Declaration of PL/SQL
tables
(OTL/OCIx)</font></b></h3>
OTL 3.x/OCIx, release OTL 3.1.0 and higher, supports PL/SQL tables via
the otl_stream class and special <a href="otl3_pl_tab.htm">template
PL/SQL
table container</a> classes. This feature works only for PL/SQL blocks
and stored procedures. For example, a stored procedure, which takes
PL/SQL
tables as arguments, gets called in a block. The PL/SQL table
containers
can be used to read/write the whole PL/SQL table from/to the OTL stream
in one shot. In the OCIx and Pro*C, it is a well known technique, only
the interface is a way too complex.
<p>In OTL 4.0/OCIx, in PL/SQL blocks, a PL/SQL table dimension can be
added
to the access qualifiers <b>in</b>/<b>out</b>/<b>inout</b>, e.g.:
</p>
<pre>&nbsp;BEGIN<br>&nbsp;&nbsp; my_pkg.my_proc(:salary&lt;float,in<b>[100]</b>&gt;,&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :ID&lt;int,inout<b>[200]</b>&gt;,&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :name&lt;char[32],out<b>[150]</b>&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );<br>&nbsp;END;</pre>
[100] is the maximum size of the <i>:salary</i> placeholder, which is
an
input PL/SQL table of float[100]. [200] is the maximum size of the <i>:ID</i>
placeholder, which is an input/output PL/SQL table of int[100]. [150]
is
the maximum size of the <i>:name</i> placeholder, which is an output
PL/SQL
table of char[150][32].
<p>The size of the otl_stream with the definition in the example above
needs to be set to 1, since stored procedures cannot be called in bulk.
However, PL/SQL table type parameters are not scalars, they are vectors
with maximum sizes, predefined in the defintions of the bind variables.
</p>
<p><a name="PLSQL_table_size"></a>Starting with OTL 4.0.115 and on, the
maximum PL/SQL table size is no longer limited to 32767. In order to
turn the old limit of 32767 back on, use #define <a
 href="otl3_compile.htm#OTL_STREAM_LEGACY_BUFFER_SIZE_TYPE">OTL_STREAM_LEGACY_BUFFER_SIZE_TYPE</a>.<br>
</p>
<p>For more detail, see examples <a href="otl3_ex49.htm">49</a>, <a
 href="otl3_ex52.htm">50,
51, 52.</a>
</p>
<center>
<p></p>
<hr width="100%">
<p><a href="otl3_class.htm">Prev</a> <a href="otl3_connect_class.htm">Next</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
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 + -