如何调用OCI从ORACLE的功能? [英] How do I call an ORACLE function from OCI?

查看:134
本文介绍了如何调用OCI从ORACLE的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以通过这个命令构建SQL命令在C程序中调用Oracle存储过程通过OCI,这里是从我的code简短的片段:

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);

但我怎么构建一个电话(在我的C程序)到Oracle功能具有以下签名:

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

要调用PL / SQL函数我会用,例如:

To call the function in PL/SQL I would use for example:

      v_seq := get_seq_number(v_tabname, v_seqtype);

我如何构造SQL字符数组(sql_stmt)来调用Oracle函数在我的C程序?

How do I construct the SQL character array (sql_stmt) to call the ORACLE function in my C program ?

推荐答案

构造您的SQL说明书如下:

Construct your SQL statment as follows

strcpy ( sql_stmt, "BEGIN :v_seq := get_seq_number(:v_tabname, :v_seqtype); END;" );

prepare您的语句,previously。绑定通过名称的变量(包括 v_seq 为您的code previous并执行该语句当过程完成,值:v_seq会正确设置。

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.

这篇关于如何调用OCI从ORACLE的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆