📄 group__g__demo.html
字号:
<a class="code" href="group__g__exec.html#gf2163ec44e644cc734c393188707985b" title="Parse and execute a SQL statement or PL/SQL block.">OCI_ExecuteStmt</a>(st, MT(<span class="stringliteral">"insert into test_coll_varray(departement,employees) "</span>) MT(<span class="stringliteral">"values (2, t_tab1_emp('Ben', 'Alice', 'Joel', 'Maria'))"</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, MT(<span class="stringliteral">"insert into test_coll_nested(departement,employees) "</span>) MT(<span class="stringliteral">"values (1, t_tab2_emp('Vince', 'Richard', 'Rita', 'Sophia'))"</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, MT(<span class="stringliteral">"insert into test_coll_nested(departement,employees) "</span>) MT(<span class="stringliteral">"values (2, t_tab2_emp('Paul', 'Sarah', 'Robert', 'Zoe'))"</span>)); <a class="code" href="group__g__transac.html#gee1ba614ed2dc5bd83bf788ca08f3e71" title="Commit current pending changes.">OCI_Commit</a>(cn);}<span class="comment">/* ------------------------------------------------------------------------ *</span><span class="comment"> * drop_tables</span><span class="comment"> * ------------------------------------------------------------------------ */</span><span class="keywordtype">void</span> drop_tables(<span class="keywordtype">void</span>){ print_text(<span class="stringliteral">"\n>>>>> DROPPING TABLES AND TYPES \n\n"</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, MT(<span class="stringliteral">"drop table test_fetch"</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, MT(<span class="stringliteral">"drop table test_long_str"</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, MT(<span class="stringliteral">"drop table test_long_raw"</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, MT(<span class="stringliteral">"drop table test_lob"</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, MT(<span class="stringliteral">"drop table test_array"</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, MT(<span class="stringliteral">"drop table test_object"</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, MT(<span class="stringliteral">"drop table test_coll_varray"</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, MT(<span class="stringliteral">"drop table test_coll_nested"</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, MT(<span class="stringliteral">"drop type t_test"</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, MT(<span class="stringliteral">"drop type t_type"</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, MT(<span class="stringliteral">"drop type t_tab1_emp"</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, MT(<span class="stringliteral">"drop type t_tab2_emp"</span>));}<span class="comment">/* ------------------------------------------------------------------------ *</span><span class="comment"> * test_format</span><span class="comment"> * ------------------------------------------------------------------------ */</span><span class="keywordtype">void</span> test_format(<span class="keywordtype">void</span>){ <span class="keywordtype">int</span> code = 1; print_text(<span class="stringliteral">"\n>>>>> TEST FORMATTING \n\n"</span>); <a class="code" href="group__g__format.html#ge1b4805b4ed6530b496cd637b52a2adf" title="Parse and execute a formatted SQL statement or PL/SQL block.">OCI_ExecuteStmtFmt</a>(st, MT(<span class="stringliteral">"select * from test_fetch where code = %i"</span>), code); rs = <a class="code" href="group__g__fetch.html#gf2a9e28b66a9538ba0ffb62bffb87c16" title="Retrieve the resultset handle from an executed statement.">OCI_GetResultset</a>(st); <span class="keywordflow">while</span> (<a class="code" href="group__g__fetch.html#g36ac26dcea78f6074421781e401f97ba" title="Fetch the next row of the resultset.">OCI_FetchNext</a>(rs)) { print_frmt(<span class="stringliteral">"> code : %i"</span>, <a class="code" href="group__g__fetch.html#ga8d80dc30b2012eaddd13efa9dfb711d" title="Return the current integer value of the column at the given index in the resultset...">OCI_GetInt</a>(rs, 1)); print_text(<span class="stringliteral">", action : "</span>); print_dstr(<a class="code" href="group__g__fetch.html#g755a9b07c174feacd05c86e0e44b0ab0" title="Return the current string value of the column at the given index in the resultset...">OCI_GetString</a>(rs, 2)); print_frmt(<span class="stringliteral">", price : %g"</span>, <a class="code" href="group__g__fetch.html#gdfbe8b6c23200810823e9ca6a1956cd7" title="Return the current double value of the column at the given index in the resultset...">OCI_GetDouble</a>(rs,3)); print_text(<span class="stringliteral">", date : "</span>); print_dstr(<a class="code" href="group__g__fetch.html#g755a9b07c174feacd05c86e0e44b0ab0" title="Return the current string value of the column at the given index in the resultset...">OCI_GetString</a>(rs, 4)); print_text(<span class="stringliteral">"\n"</span>); } print_frmt(<span class="stringliteral">"\n%d row(s) fetched\n"</span>, <a class="code" href="group__g__fetch.html#g93bd9197720088dbda2bef593ad1c07c" title="Retrieve the number of rows fetched so far.">OCI_GetRowCount</a>(rs));}<span class="comment">/* ------------------------------------------------------------------------ *</span><span class="comment"> * test_immediate</span><span class="comment"> * ------------------------------------------------------------------------ */</span><span class="keywordtype">void</span> test_immediate(<span class="keywordtype">void</span>){ <span class="keywordtype">int</span> code = 1; print_text(<span class="stringliteral">"\n>>>>> TEST IMMEDIATE \n\n"</span>); <a class="code" href="group__g__format.html#g85318e359913e49d5654d2f53a070ef7" title="Perform 3 calls (prepare+execute+fetch) in 1 call.">OCI_Immediate</a>(cn, MT(<span class="stringliteral">"select code, article from test_fetch where code = 1"</span>), OCI_ARG_INT, &code, OCI_ARG_TEXT, temp); print_frmt(<span class="stringliteral">"> code : %i "</span>, code); print_text(<span class="stringliteral">"- article : "</span>); print_dstr(temp); print_text(<span class="stringliteral">"\n"</span>);}<span class="comment">/* ------------------------------------------------------------------------ *</span><span class="comment"> * test_immediate_format</span><span class="comment"> * ------------------------------------------------------------------------ */</span><span class="keywordtype">void</span> test_immediate_format(<span class="keywordtype">void</span>){ <span class="keywordtype">int</span> code = 1; print_text(<span class="stringliteral">"\n>>>>> TEST IMMEDIATE FORMATTED\n\n"</span>); <a class="code" href="group__g__format.html#g845524c6dce7499a0cc27488052a93c2" title="Performs 4 call (prepare+bind+execute+fetch) in 1 call.">OCI_ImmediateFmt</a>(cn, MT(<span class="stringliteral">"select article from test_fetch where code = %i"</span>), code, OCI_ARG_TEXT, temp); print_text(<span class="stringliteral">"> article : "</span>); print_dstr(temp); print_text(<span class="stringliteral">"\n"</span>);}<span class="comment">/* ------------------------------------------------------------------------ *</span><span class="comment"> * test_fetch</span><span class="comment"> * ------------------------------------------------------------------------ */</span><span class="keywordtype">void</span> test_fetch(<span class="keywordtype">void</span>){ <span class="keywordtype">int</span> i, n; print_text(<span class="stringliteral">"\n>>>>> SIMPLE TEST FETCH WITH META DATA\n\n"</span>); <span class="comment">/* execute query in one go */</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, MT(<span class="stringliteral">"select * from test_fetch"</span>)); rs = <a class="code" href="group__g__fetch.html#gf2a9e28b66a9538ba0ffb62bffb87c16" title="Retrieve the resultset handle from an executed statement.">OCI_GetResultset</a>(st); n = <a class="code" href="group__g__fetch.html#g8935f9c6ff0d6f1d94c70afb3418a916" title="Return the number of columns in the resulset.">OCI_GetColumnCount</a>(rs); <span class="comment">/* print resultset columns info */</span> <span class="keywordflow">for</span>(i = 1; i <= n; i++) { <a class="code" href="struct_o_c_i___column.html" title="Oracle SQL Column and Type member representation.">OCI_Column</a> *col = <a class="code" href="group__g__fetch.html#g7b64be082fc14ac73347b081cdb66de0" title="Return the column object handle at the given index in the resultset.">OCI_GetColumn</a>(rs, i); print_frmt(<span class="stringliteral">"> Field : #%i "</span>, i); print_text(<span class="stringliteral">"- Name : "</span>); print_mstr(<a class="code" href="group__g__fetch.html#gd22f87322cdb788a03a0c259ab126a94" title="Return the name of the given column.">OCI_ColumnGetName</a>(col)); print_text(<span class="stringliteral">"\n"</span>); } print_text(<span class="stringliteral">"\n"</span>); <span class="comment">/* print resultset content */</span> <span class="keywordflow">while</span> (<a class="code" href="group__g__fetch.html#g36ac26dcea78f6074421781e401f97ba" title="Fetch the next row of the resultset.">OCI_FetchNext</a>(rs)) { print_frmt(<span class="stringliteral">"> code : %i"</span>, <a class="code" href="group__g__fetch.html#ga8d80dc30b2012eaddd13efa9dfb711d" title="Return the current integer value of the column at the given index in the resultset...">OCI_GetInt</a>(rs, 1)); print_text(<span class="stringliteral">", action : "</span>); print_dstr(<a class="code" href="group__g__fetch.html#g755a9b07c174feacd05c86e0e44b0ab0" title="Return the current string value of the column at the given index in the resultset...">OCI_GetString</a>(rs, 2)); print_frmt(<span class="stringliteral">", price : %g"</span>, <a class="code" href="group__g__fetch.html#gdfbe8b6c23200810823e9ca6a1956cd7" title="Return the current double value of the column at the given index in the resultset...">OCI_GetDouble</a>(rs,3)); print_text(<span class="stringliteral">", date : "</span>); print_dstr(<a class="code" href="group__g__fetch.html#g755a9b07c174feacd05c86e0e44b0ab0" title="Return the current string value of the column at the given index in the resultset...">OCI_GetString</a>(rs, 4)); print_text(<span class="stringliteral">"\n"</span>); } print_frmt(<span class="stringliteral">"\n%d row(s) fetched\n"</span>, <a class="code" href="group__g__fetch.html#g93bd9197720088dbda2bef593ad1c07c" title="Retrieve the number of rows fetched so far.">OCI_GetRowCount</a>(rs));}<span class="comment">/* ------------------------------------------------------------------------ *</span><span class="comment"> * test_bind1</span><span class="comment"> * ------------------------------------------------------------------------ */</span><span class="keywordtype">void</span> test_bind1(<span class="keywordtype">void</span>){ <span class="keywordtype">int</span> code = 1; print_text(<span class="stringliteral">"\n>>>>> TEST BINDING \n\n"</span>); <span class="comment">/* execute query in three steps */</span> <a class="code" href="group__g__exec.html#gd5a7fcffe7d24da001e44636cfc06578" title="Prepare a SQL statement or PL/SQL block.">OCI_Prepare</a>(st, MT(<span class="stringliteral">"select * from test_fetch where code = :code"</span>)); <a class="code" href="group__g__bind.html#g4d08024d2242b6140fecea8c2ec05c81" title="Bind an integer variable.">OCI_BindInt</a>(st, MT(<span class="stringliteral">":code"</span>), &code); <a class="code" href="group__g__exec.html#g7189aa353845909aaedc8d5956429450" title="Execute a prepared SQL statement or PL/SQL block.">OCI_Execute</a>(st); rs = <a class="code" href="group__g__fetch.html#gf2a9e28b66a9538ba0ffb62bffb87c16" title="Retrieve the resultset handle from an executed statement.">OCI_GetResultset</a>(st); <span class="comment">/* print resultset content */</span> <span class="keywordflow">while</span> (<a class="code" href="group__g__fetch.html#g36ac26dcea78f6074421781e401f97ba" title="Fetch the next row of the resultset.">OCI_FetchNext</a>(rs)) { print_frmt(<span class="stringliteral">"> code : %i"</span>, <a class="code" href="group__g__fetch.html#ga8d80dc30b2012eaddd13efa9dfb711d" title="Return the current integer value of the column at the given index in the resultset...">OCI_GetInt</a>(rs, 1)); print_text(<span class="stringliteral">", action : "</span>); print_dstr(<a class="code" href="group__g__fetch.html#g755a9b07c174feacd05c86e0e44b0ab0" title="Return the current string value of the column at the given index in the resultset...">OCI_GetString</a>(rs, 2)); print_frmt(<span class="stringliteral">", price : %g"</span>, <a class="code" href="group__g__fetch.html#gdfbe8b6c23200810823e9ca6a1956cd7" title="Return the current double value of the column at the given index in the resultset...">OCI_GetDouble</a>(rs,3)); print_text(<span class="stringliteral">", date : "</span>); print_dstr(<a class="code" href="group__g__fetch.html#g755a9b07c174feacd05c86e0e44b0ab0" title="Return the current string value of the column at the given index in the resultset...">OCI_GetString</a>(rs, 4)); print_text(<span class="stringliteral">"\n"</span>); } print_frmt(<span class="stringliteral">"\n%d row(s) fetched\n"</span>, <a class="code" href="group__g__fetch.html#g93bd9197720088dbda2bef593ad1c07c" title="Retrieve the number of rows fetched so far.">OCI_GetRowCount</a>(rs));}<span class="comment">/* ------------------------------------------------------------------------ *</span>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -