如何从 OCI 调用 ORACLE 函数?
我可以通过在 C 程序中构造 SQL 命令来通过 C 程序中的 OCI 调用 ORACLE 存储过程,这是我的代码的简短片段:
/* build sql statement calling stored procedure */
strcpy ( sql_stmt, "call get_tab_info(:x)" );
rc = OCIStmtPrepare(p_sql, p_err, sql_stmt,
(ub4) strlen (sql_stmt), (ub4) OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT);
但是如何使用以下代码构造对 ORACLE 函数的调用(在我的 C 程序中)签名:
CREATE OR REPLACE FUNCTION get_seq_number (p_table_name IN VARCHAR2, p_seq_type IN VARCHAR2)
RETURN NUMBER IS
要在 PL/SQL 中调用函数,我将使用例如:
v_seq := get_seq_number(v_tabname, v_seqtype);
如何构造 SQL 字符数组 (sql_stmt) 来在我的 C 程序中调用 ORACLE 函数?
I can call an ORACLE stored procedure through OCI in a C program by constructing the SQL command for the command, here's a brief snippet from my code:
/* build sql statement calling stored procedure */
strcpy ( sql_stmt, "call get_tab_info(:x)" );
rc = OCIStmtPrepare(p_sql, p_err, sql_stmt,
(ub4) strlen (sql_stmt), (ub4) OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT);
But how do I construct a call (in my C program) to an ORACLE function with the following signature:
CREATE OR REPLACE FUNCTION get_seq_number (p_table_name IN VARCHAR2, p_seq_type IN VARCHAR2)
RETURN NUMBER IS
To call the function in PL/SQL I would use for example:
v_seq := get_seq_number(v_tabname, v_seqtype);
How do I construct the SQL character array (sql_stmt) to call the ORACLE function in my C program ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
按如下方式构建 SQL 语句
按照之前的方式准备语句。 按名称绑定变量(包括代码中前面的
v_seq
)并执行语句。过程完成后,:v_seq 的值将被正确设置。Construct your SQL statment as follows
Prepare your statement as previously. Bind the variables by name (including the
v_seq
as previous in your code and execute the statement. When the procedure completes, the value of :v_seq will be set correctly.您可以发出:
并像
SELECT 查询
中那样解析结果,或者调用匿名 block:并将
:test
绑定为输出参数。You either issue:
and parse the result as in
SELECT query
, or call anonymous block:, and bind
:test
as an output parameter.