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

📄 group__g__exec.html

📁 oci的源码,可以在任何平台上编译,相当方便实用
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"><title>OCILIB (C Driver for Oracle): Executing statements</title><link href="doxygen.css" rel="stylesheet" type="text/css"><link href="tabs.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.5.4 --><div class="tabs">  <ul>    <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>    <li><a href="modules.html"><span>Modules</span></a></li>    <li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>    <li><a href="files.html"><span>Files</span></a></li>  </ul></div><h1>Executing statements</h1><hr><a name="_details"></a><h2>Detailed Description</h2>Executing SQL statements or PL/SQL blocks is really simple with OCILIB.<p>First, call <a class="el" href="group__g__exec.html#g335822f983af0fb5c529431f06a9a17b" title="Create a statement object and return its handle.">OCI_StatementCreate()</a> to allocate a statement handle. Then :<p><ul><li>Parse the SQL with <a class="el" href="group__g__exec.html#gd5a7fcffe7d24da001e44636cfc06578" title="Prepare a SQL statement or PL/SQL block.">OCI_Prepare()</a></li><li>Execute it with <a class="el" href="group__g__exec.html#g7189aa353845909aaedc8d5956429450" title="Execute a prepared SQL statement or PL/SQL block.">OCI_Execute()</a></li></ul><p>These two steps can be done together by calling <a class="el" href="group__g__exec.html#gf2163ec44e644cc734c393188707985b" title="Parse and execute a SQL statement or PL/SQL block.">OCI_ExecuteStmt()</a> that parses and executes in one go.<p>To find out if the statement has affected any rows, call <a class="el" href="group__g__exec.html#g1cf932261960da80cd36d650a08565c3" title="Return the number of rows affected by the SQL statement.">OCI_GetAffectedRows()</a><p>Finally, release the statement and its resources with <a class="el" href="group__g__exec.html#g487b4f90f1fd4aee18f3d901f5aed104" title="Free a statement and all resources associated to it (resultsets, ....).">OCI_StatementFree()</a><p><dl class="note" compact><dt><b>Note:</b></dt><dd>A statement can be parsed once and executed as many times as needed (see Binding variables section)<p>A <a class="el" href="struct_o_c_i___statement.html" title="Oracle SQL or PL/SQL statement.">OCI_Statement</a> can be used to prepare and/or execute different SQL and PL/SQL statements as many times as needed. For example, if the SQL processing of an application is sequential, only one statement handle is required<p>OCILIB supports nested levels of SQL statement processing. An application can loop through the resultset of the statement handle A, executing statement B and fetching statement C at every loop, and so on ...</dd></dl><dl class="user" compact><dt><b>Example</b></dt><dd><div class="fragment"><pre class="fragment"><span class="preprocessor">#include "ocilib.h"</span><span class="keywordtype">int</span> main(<span class="keywordtype">void</span>){    <a class="code" href="struct_o_c_i___connection.html" title="Oracle physical connection.">OCI_Connection</a> *cn;    <a class="code" href="struct_o_c_i___statement.html" title="Oracle SQL or PL/SQL statement.">OCI_Statement</a>  *st;      <span class="keywordflow">if</span> (!<a class="code" href="group__g__init.html#gcdb642d75f7c8478e083634144bc813c" title="Initializes the library.">OCI_Initialize</a>(NULL, NULL, OCI_ENV_DEFAULT))        <span class="keywordflow">return</span> EXIT_FAILURE;    cn = <a class="code" href="group__g__connect.html#gdb6e2cdf759587dd81c2fda7c5f44338" title="Create a physical connection to an Oracle database server.">OCI_ConnectionCreate</a>(<span class="stringliteral">"db"</span>, <span class="stringliteral">"usr"</span>, <span class="stringliteral">"pwd"</span>, OCI_SESSION_DEFAULT);    st = <a class="code" href="group__g__exec.html#g335822f983af0fb5c529431f06a9a17b" title="Create a statement object and return its handle.">OCI_StatementCreate</a>(cn);     <span class="comment">/* prepare and execute in 2 steps */</span>    <a class="code" href="group__g__exec.html#gd5a7fcffe7d24da001e44636cfc06578" title="Prepare a SQL statement or PL/SQL block.">OCI_Prepare</a>(st, <span class="stringliteral">"delete from test_fetch where code &gt; 10"</span>);    <a class="code" href="group__g__exec.html#g7189aa353845909aaedc8d5956429450" title="Execute a prepared SQL statement or PL/SQL block.">OCI_Execute</a>(st);    <span class="comment">/* prepare/execute in 1 step */</span>    <a class="code" href="group__g__exec.html#gf2163ec44e644cc734c393188707985b" title="Parse and execute a SQL statement or PL/SQL block.">OCI_ExecuteStmt</a>(st, <span class="stringliteral">"delete from test_fetch where code &gt; 1"</span>);    printf(<span class="stringliteral">"%d row deleted"</span>, <a class="code" href="group__g__exec.html#g1cf932261960da80cd36d650a08565c3" title="Return the number of rows affected by the SQL statement.">OCI_GetAffectedRows</a>(st));    <a class="code" href="group__g__transac.html#gee1ba614ed2dc5bd83bf788ca08f3e71" title="Commit current pending changes.">OCI_Commit</a>(cn);    <a class="code" href="group__g__init.html#g639706aa8e9689c7ebffc018fac6d3ae" title="Clean up all resources allocated by the library.">OCI_Cleanup</a>();     <span class="keywordflow">return</span> EXIT_SUCCESS;}</pre></div> </dd></dl><p><table border="0" cellpadding="0" cellspacing="0"><tr><td></td></tr><tr><td colspan="2"><br><h2>Functions</h2></td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">OCI_EXPORT <a class="el" href="struct_o_c_i___statement.html">OCI_Statement</a> *OCI_API&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__g__exec.html#g335822f983af0fb5c529431f06a9a17b">OCI_StatementCreate</a> (<a class="el" href="struct_o_c_i___connection.html">OCI_Connection</a> *con)</td></tr><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Create a statement object and return its handle.  <a href="#g335822f983af0fb5c529431f06a9a17b"></a><br></td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">OCI_EXPORT boolean OCI_API&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__g__exec.html#g487b4f90f1fd4aee18f3d901f5aed104">OCI_StatementFree</a> (<a class="el" href="struct_o_c_i___statement.html">OCI_Statement</a> *stmt)</td></tr><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Free a statement and all resources associated to it (resultsets, ....).  <a href="#g487b4f90f1fd4aee18f3d901f5aed104"></a><br></td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">OCI_EXPORT boolean OCI_API&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__g__exec.html#gd5a7fcffe7d24da001e44636cfc06578">OCI_Prepare</a> (<a class="el" href="struct_o_c_i___statement.html">OCI_Statement</a> *stmt, const mtext *sql)</td></tr><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Prepare a SQL statement or PL/SQL block.  <a href="#gd5a7fcffe7d24da001e44636cfc06578"></a><br></td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">OCI_EXPORT boolean OCI_API&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__g__exec.html#g7189aa353845909aaedc8d5956429450">OCI_Execute</a> (<a class="el" href="struct_o_c_i___statement.html">OCI_Statement</a> *stmt)</td></tr><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Execute a prepared SQL statement or PL/SQL block.  <a href="#g7189aa353845909aaedc8d5956429450"></a><br></td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">OCI_EXPORT boolean OCI_API&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__g__exec.html#gf2163ec44e644cc734c393188707985b">OCI_ExecuteStmt</a> (<a class="el" href="struct_o_c_i___statement.html">OCI_Statement</a> *stmt, const mtext *sql)</td></tr><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Parse and execute a SQL statement or PL/SQL block.  <a href="#gf2163ec44e644cc734c393188707985b"></a><br></td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">OCI_EXPORT const mtext *OCI_API&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__g__exec.html#g05c6c5af87cdff3a231755cfd44e133f">OCI_GetSql</a> (<a class="el" href="struct_o_c_i___statement.html">OCI_Statement</a> *stmt)</td></tr><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Return the last SQL or PL/SQL statement parsed by the statement.  <a href="#g05c6c5af87cdff3a231755cfd44e133f"></a><br></td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">OCI_EXPORT unsigned int OCI_API&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__g__exec.html#gddfbdd24d8686d908e560611bb7b6cc7">OCI_GetSqlErrorPos</a> (<a class="el" href="struct_o_c_i___statement.html">OCI_Statement</a> *stmt)</td></tr><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Return the error position in the SQL statement where the error occurred in case of SQL parsing error.  <a href="#gddfbdd24d8686d908e560611bb7b6cc7"></a><br></td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">OCI_EXPORT unsigned int OCI_API&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__g__exec.html#g1cf932261960da80cd36d650a08565c3">OCI_GetAffectedRows</a> (<a class="el" href="struct_o_c_i___statement.html">OCI_Statement</a> *stmt)</td></tr><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Return the number of rows affected by the SQL statement.  <a href="#g1cf932261960da80cd36d650a08565c3"></a><br></td></tr></table><hr><h2>Function Documentation</h2><a class="anchor" name="g7189aa353845909aaedc8d5956429450"></a><!-- doxytag: member="ocilib.h::OCI_Execute" ref="g7189aa353845909aaedc8d5956429450" args="(OCI_Statement *stmt)" --><div class="memitem"><div class="memproto">      <table class="memname">        <tr>          <td class="memname">OCI_EXPORT boolean OCI_API OCI_Execute           </td>          <td>(</td>          <td class="paramtype"><a class="el" href="struct_o_c_i___statement.html">OCI_Statement</a> *&nbsp;</td>          <td class="paramname"> <em>stmt</em>          </td>          <td>&nbsp;)&nbsp;</td>          <td width="100%"></td>        </tr>      </table></div><div class="memdoc"><p>Execute a prepared SQL statement or PL/SQL block. <p><dl compact><dt><b>Parameters:</b></dt><dd>  <table border="0" cellspacing="2" cellpadding="0">    <tr><td valign="top"></td><td valign="top"><em>stmt</em>&nbsp;</td><td>- Statement handle</td></tr>  </table></dl><dl class="return" compact><dt><b>Returns:</b></dt><dd>TRUE on success otherwise FALSE </dd></dl><p>Definition at line <a class="el" href="statement_8c-source.html#l01251">1251</a> of file <a class="el" href="statement_8c-source.html">statement.c</a>.</p><p>References <a class="el" href="ocilib__types_8h-source.html#l00270">OCI_Connection::autocom</a>, <a class="el" href="ocilib__types_8h-source.html#l00414">OCI_Statement::con</a>, <a class="el" href="ocilib__types_8h-source.html#l00269">OCI_Connection::cxt</a>, <a class="el" href="ocilib__types_8h-source.html#l00267">OCI_Connection::err</a>, <a class="el" href="ocilib__types_8h-source.html#l00435">OCI_Statement::err_pos</a>, <a class="el" href="ocilib__types_8h-source.html#l00423">OCI_Statement::exec_mode</a>, <a class="el" href="ocilib__types_8h-source.html#l00431">OCI_Statement::nb_iters</a>, <a class="el" href="group__g__transac.html#gee1ba614ed2dc5bd83bf788ca08f3e71">OCI_Commit()</a>, <a class="el" href="group__g__fetch.html#ge4eebf1424c98a7c58f90f673772b7ec">OCI_ReleaseResultsets()</a>, <a class="el" href="ocilib__types_8h-source.html#l00429">OCI_Statement::status</a>, <a class="el" href="ocilib__types_8h-source.html#l00411">OCI_Statement::stmt</a>, and <a class="el" href="ocilib__types_8h-source.html#l00430">OCI_Statement::type</a>.</p><p>Referenced by <a class="el" href="group__g__exec.html#gf2163ec44e644cc734c393188707985b">OCI_ExecuteStmt()</a>, <a class="el" href="group__g__format.html#ge1b4805b4ed6530b496cd637b52a2adf">OCI_ExecuteStmtFmt()</a>, <a class="el" href="group__g__format.html#g845524c6dce7499a0cc27488052a93c2">OCI_ImmediateFmt()</a>, <a class="el" href="group__g__plsql.html#geff8f38ba15b9e757cec70d91e4ffe13">OCI_ServerEnableOutput()</a>, and <a class="el" href="group__g__plsql.html#gbb13df960f035cd9e48e774c39db425a">OCI_ServerGetOutput()</a>.</p></div></div><p><a class="anchor" name="gf2163ec44e644cc734c393188707985b"></a><!-- doxytag: member="ocilib.h::OCI_ExecuteStmt" ref="gf2163ec44e644cc734c393188707985b" args="(OCI_Statement *stmt, const mtext *sql)" --><div class="memitem"><div class="memproto">      <table class="memname">        <tr>          <td class="memname">OCI_EXPORT boolean OCI_API OCI_ExecuteStmt           </td>          <td>(</td>          <td class="paramtype"><a class="el" href="struct_o_c_i___statement.html">OCI_Statement</a> *&nbsp;</td>          <td class="paramname"> <em>stmt</em>, </td>        </tr>        <tr>          <td class="paramkey"></td>          <td></td>          <td class="paramtype">const mtext *&nbsp;</td>          <td class="paramname"> <em>sql</em></td><td>&nbsp;</td>        </tr>        <tr>          <td></td>          <td>)</td>          <td></td><td></td><td width="100%"></td>        </tr>      </table></div><div class="memdoc"><p>Parse and execute a SQL statement or PL/SQL block. <p><dl compact><dt><b>Parameters:</b></dt><dd>  <table border="0" cellspacing="2" cellpadding="0">    <tr><td valign="top"></td><td valign="top"><em>stmt</em>&nbsp;</td><td>- Statement handle </td></tr>    <tr><td valign="top"></td><td valign="top"><em>sql</em>&nbsp;</td><td>- SQL order - PL/SQL block</td></tr>  </table></dl><dl class="return" compact><dt><b>Returns:</b></dt><dd>TRUE on success otherwise FALSE </dd></dl><p>Definition at line <a class="el" href="statement_8c-source.html#l01327">1327</a> of file <a class="el" href="statement_8c-source.html">statement.c</a>.</p><p>References <a class="el" href="group__g__exec.html#g7189aa353845909aaedc8d5956429450">OCI_Execute()</a>, and <a class="el" href="group__g__exec.html#gd5a7fcffe7d24da001e44636cfc06578">OCI_Prepare()</a>.</p><p>Referenced by <a class="el" href="group__g__format.html#g85318e359913e49d5654d2f53a070ef7">OCI_Immediate()</a>, and <a class="el" href="group__g__plsql.html#g0d3321a0abff0722baf6b2b7233f4cb5">OCI_ServerDisableOutput()</a>.</p></div></div><p><a class="anchor" name="g1cf932261960da80cd36d650a08565c3"></a><!-- doxytag: member="ocilib.h::OCI_GetAffectedRows" ref="g1cf932261960da80cd36d650a08565c3" args="(OCI_Statement *stmt)" --><div class="memitem"><div class="memproto">      <table class="memname">        <tr>          <td class="memname">OCI_EXPORT unsigned int OCI_API OCI_GetAffectedRows           </td>          <td>(</td>          <td class="paramtype"><a class="el" href="struct_o_c_i___statement.html">OCI_Statement</a> *&nbsp;</td>          <td class="paramname"> <em>stmt</em>          </td>          <td>&nbsp;)&nbsp;</td>          <td width="100%"></td>        </tr>      </table></div><div class="memdoc"><p>Return the number of rows affected by the SQL statement. <p><dl compact><dt><b>Parameters:</b></dt><dd>  <table border="0" cellspacing="2" cellpadding="0">    <tr><td valign="top"></td><td valign="top"><em>stmt</em>&nbsp;</td><td>- Statement handle</td></tr>  </table></dl>The returned value is :<p><ul>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -