📄 ex17_8c-example.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>libsqlora8: Example Documentation</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.3.6 --><div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related Pages</a> | <a class="qindex" href="examples.html">Examples</a></div><h1>ex17.c</h1>Example for selecting from a refcursor. <div class="fragment"><pre><span class="comment">/* $Id: ex17.c,v 1.3 2002/08/24 12:54:47 kpoitschke Exp $ */</span><span class="preprocessor">#include <stdio.h></span><span class="preprocessor">#include <stdlib.h></span><span class="preprocessor">#include "examples.h"</span><span class="keywordtype">int</span> select_refcursor(<a class="code" href="group__typedefs.html#ga0">sqlo_db_handle_t</a> dbh, <span class="keywordtype">double</span> min_salary){ <a class="code" href="group__typedefs.html#ga1">sqlo_stmt_handle_t</a> sth = <a class="code" href="group__constants.html#gga5a49">SQLO_STH_INIT</a>; <a class="code" href="group__typedefs.html#ga1">sqlo_stmt_handle_t</a> st2h; <span class="comment">/* handle of the ref cursor */</span> <span class="keywordtype">double</span> sal = min_salary; CONST <span class="keywordtype">char</span> **v; <span class="keywordtype">int</span> status; CONST <span class="keywordtype">char</span> * stmt = <span class="stringliteral">"BEGIN\n"</span> <span class="stringliteral">" OPEN :c1 FOR SELECT ENAME, SAL FROM EMP WHERE SAL >= :min_sal ORDER BY 2,1;\n"</span> <span class="stringliteral">"END;\n"</span>; <span class="comment">/* parse the statement */</span> <span class="keywordflow">if</span> ( 0 <= (sth = <a name="a47"></a><a class="code" href="group__complex.html#ga186">sqlo_prepare</a>(dbh, stmt))) { <span class="comment">/* bind all variables */</span> <span class="keywordflow">if</span> (<a class="code" href="group__constants.html#gga3a25">SQLO_SUCCESS</a> != ( <a name="a48"></a><a class="code" href="group__complex.html#ga2">sqlo_bind_ref_cursor</a>(sth, <span class="stringliteral">":c1"</span>, &st2h)) || (<a name="a49"></a><a class="code" href="group__complex.html#ga187">sqlo_bind_by_name</a>(sth, <span class="stringliteral">":min_sal"</span>, SQLOT_FLT, &sal, <span class="keyword">sizeof</span>(sal), 0, 0) ) ) { error_exit(dbh, <span class="stringliteral">"sqlo_bind_by_name"</span>); } <span class="keywordflow">else</span> { <span class="comment">/* execute the PL/SQL block */</span> <span class="keywordflow">if</span> (<a class="code" href="group__constants.html#gga3a25">SQLO_SUCCESS</a> != <a name="a50"></a><a class="code" href="group__complex.html#ga194">sqlo_execute</a>(sth, 1)) error_exit(dbh, <span class="stringliteral">"sqlo_execute"</span>); } <span class="comment">/* execute the refcursor */</span> <span class="keywordflow">if</span> (<a class="code" href="group__constants.html#gga3a25">SQLO_SUCCESS</a> != <a class="code" href="group__complex.html#ga194">sqlo_execute</a>(st2h, 1)) { error_exit(dbh, <span class="stringliteral">"sqlo_execute(ref)"</span>); } <span class="keywordflow">while</span> (<a class="code" href="group__constants.html#gga3a25">SQLO_SUCCESS</a> == (status = <a name="a51"></a><a class="code" href="group__easy.html#ga167">sqlo_fetch</a>(st2h, 1))) { v = <a name="a52"></a><a class="code" href="group__easy.html#ga168">sqlo_values</a>(st2h, NULL, 1); printf(<span class="stringliteral">"Name=%-8s Salary= %-6s\n"</span>, v[0], v[1]); } <span class="keywordflow">if</span> (status != <a class="code" href="group__constants.html#gga3a32">SQLO_NO_DATA</a>) error_exit(dbh, <span class="stringliteral">"sqlo_fetch(st2)"</span>); <span class="keywordflow">if</span> (<a class="code" href="group__constants.html#gga3a25">SQLO_SUCCESS</a> != <a name="a53"></a><a class="code" href="group__easy.html#ga172">sqlo_close</a>(sth)) error_exit(dbh, <span class="stringliteral">"sqlo_close(1)"</span>); <span class="keywordflow">if</span> (<a class="code" href="group__constants.html#gga3a25">SQLO_SUCCESS</a> != <a class="code" href="group__easy.html#ga172">sqlo_close</a>(st2h)) error_exit(dbh, <span class="stringliteral">"sqlo_close(2)"</span>); } <span class="keywordflow">else</span> { error_exit(dbh, <span class="stringliteral">"sqlo_prepare"</span>); } <span class="keywordflow">return</span> 1;}<span class="comment">/* $Id: ex17.c,v 1.3 2002/08/24 12:54:47 kpoitschke Exp $ */</span></pre></div> <hr size="1"><address style="align: right;"><small>Generated on Sun Jun 13 04:51:41 2004 for libsqlora8 by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 > </a>1.3.6 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -