免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2479 | 回复: 6
打印 上一主题 下一主题

求助OCI方面内容 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-02-03 22:30 |只看该作者 |倒序浏览
我刚开始接触OCI方面的内容,是在linux下,用C编程,操作ORACLE库,我试着安照资料的介绍编写的一点试验程序,编译通不过。我主要是完成用oci来操纵oralce数据库,能方便的操纵数据库里面的表,如select,insert,update等。请帮我列一下所用的函数和详细使用方法,以及需要的库文件等知识,若有源文件,那是最好不过了,本人十二万分的感谢。
我编的程序如下:oci_login1.c

/*OCI与ORACLE进行连接*/

#include <stdio.h>;
#include <string.h>;
#include <ocidfn.h>;
#include <oci.h>;
#include <ociapr.h>;
#include <oratypes.h>;
#include <ocidem.h>;
/*建立登录数据区*/
Lda_Def lda;
/*建立宿主数据区*/
ub1 had[256];
/*建立光标数据区*/
Cda_Def cda;
/*初始化数据库名和口令*/
text *uid="dbtest/dbtest";
/*定义一个串变量sql语句,并用PL/SQL块来初始化它*/
char sql_statament[]="select * from emp;";
/*连接数据库*/
if (orlon(&lda,&had,uid,-1,(text*)0,-1,0))
{   /*连接失败*/
error_handler(&lda);
exit(EXIT_FAILURE);
}
/*打开光标*/
if (oopen(&lda,&cda,0,0,0,0,0))
{  /*打开光标失败 */
   printf("Cannot open cursor, exiting......\n";
   exit(1);
}
        编译:  gcc -o oci oci_login1.c -I/opt/oracle/product/9.2.0/rdbms/demo -I /opt/oracle/product/9.2.0/rdbms/public/
出现错误:
/tmp/cch0Ysyf.o: In function `main':
/tmp/cch0Ysyf.o(.text+0x1c): undefined reference to `olon'
/tmp/cch0Ysyf.o(.text+0x5c): undefined reference to `oopen'
/tmp/cch0Ysyf.o(.text+0x82): undefined reference to `ologof'
/tmp/cch0Ysyf.o(.text+0xa: undefined reference to `oparse'
/tmp/cch0Ysyf.o(.text+0xb6): undefined reference to `oci_error'
/tmp/cch0Ysyf.o(.text+0xc3): undefined reference to `oexec'
/tmp/cch0Ysyf.o(.text+0xd1): undefined reference to `oci_error'
/tmp/cch0Ysyf.o(.text+0xde): undefined reference to `oclose'
/tmp/cch0Ysyf.o(.text+0x101): undefined reference to `ologof'
collect2: ld returned 1 exit status

我用此法编译了demo下的cdemo1.c,出现类似的错误。我不知为什么?
  我非常急用,恳请能尽快给予帮助!多谢!

论坛徽章:
0
2 [报告]
发表于 2004-02-04 11:29 |只看该作者

求助OCI方面内容

我用过,下午帮你看看,

论坛徽章:
0
3 [报告]
发表于 2004-02-04 14:00 |只看该作者

求助OCI方面内容

GZ

论坛徽章:
0
4 [报告]
发表于 2004-02-05 11:40 |只看该作者

求助OCI方面内容

我写的一段测试文件。你看看,可能有帮助。

#include <stdio.h>;
#include <oci.h>;
#include <iostream.h>;
#include <newsLogin.hh>;

void main(int argc, char* argv[])
{
  sword status;
  sb4 errcode;
  text info[512];

  text* username=(text*)"news";
  text* password=(text*)"news";
  text* server=(text*)"";

  status=newsLogin_news(server,username,password);
  if(status!=OCI_SUCCESS) {
                printf("SrcLogin error.\n";
//                exit(0);
  }
  OCIEnv     *envhp;
  OCIError   *errhp;
  OCIServer  *srvhp;
  OCISvcCtx  *svchp;
  OCISession *authp;
  CLIENT     *client;      /*  remote file operation  */

char _text_string[48];
float _level_pos;
float _vert_pos;
int _history_idx=1234;
int _index=4;


  OCIStmt *stmthp;
  OCIBind *bndp1 = (OCIBind *)0;
  OCIBind *bndp2 = (OCIBind *)0;
  OCIDefine *defnp1 = (OCIDefine *)0;
  OCIDefine *defnp2 = (OCIDefine *)0;
  OCIDefine *defnp3 = (OCIDefine *)0;
  text* s_st=(text*)"SELECT text_string,level_position,
                        vert_position FROM textingeosection WHERE his_stage_idx=:his_stage_id AND gsect_text_idx=:gsect_text_idx";
// allocate statement handle
  status=OCIHandleAlloc((dvoid *) envhp,(dvoid **)&stmthp,
                        OCI_HTYPE_STMT,(size_t)0,(dvoid **)0);
// prepare statement
  status=OCIStmtPrepare(stmthp,errhp,s_st,
                        (ub4)strlen((char *)s_st),
                        (ub4)OCI_NTV_SYNTAX,(ub4)OCI_DEFAULT);

// bind

  status=OCIBindByName(stmthp,&bndp1,errhp,(text *)":his_stage_id",
                        -1,(dvoid *)&_history_idx,sizeof(_history_idx),SQLT_INT,(dvoid *)0,
                        (ub2 *)0,(ub2 *)0,(ub4)0,(ub4 *)0,OCI_DEFAULT);
  status=OCIBindByName(stmthp,&bndp2,errhp,(text *)":gsect_text_idx",
                        -1,(dvoid *)&_index,sizeof(_index),SQLT_INT,(dvoid *)0,
                        (ub2 *)0,(ub2 *)0,(ub4)0,(ub4 *)0,OCI_DEFAULT);
  ub4 ind[3];
  ub2 rlen[3],rcode[3];

  status=OCIDefineByPos(stmthp,&defnp1,errhp,1,(dvoid *)_text_string,
                  48,SQLT_STR,&ind[0],&rlen[0],&rcode[0],OCI_DEFAULT);
  status=OCIDefineByPos(stmthp,&defnp2,errhp,2,(dvoid *)&_level_pos,
                  sizeof(_level_pos),SQLT_FLT,&ind[1],&rlen[1],&rcode[1],OCI_DEFAULT);
  status=OCIDefineByPos(stmthp,&defnp3,errhp,3,(dvoid *)&_vert_pos,
                  sizeof(_vert_pos),SQLT_FLT,&ind[2],&rlen[2],&rcode[2],OCI_DEFAULT);

//execute
  status=OCIStmtExecute(svchp,stmthp,errhp,(ub4)1,(ub4)0,
               (CONST OCISnapshot *)NULL,(OCISnapshot *)NULL,OCI_DEFAULT);
  OCIHandleFree((dvoid *)stmthp, (ub4) OCI_HTYPE_STMT);

cout<<"_text_string=="<<_text_string<<endl;
cout<<"_level_pos=="<<_level_pos<<endl;
cout<<"_vert_pos==="<<_vert_pos<<endl;

  status=newsLogoff_news();
}

论坛徽章:
0
5 [报告]
发表于 2004-02-06 09:36 |只看该作者

求助OCI方面内容

你的步骤基本正确,
1连接数据库。
2执行语句。
3绑定条件变量(无WHERE,就不要此句)
4定义输出变量。
5提交。

论坛徽章:
0
6 [报告]
发表于 2006-06-01 21:43 |只看该作者
楼主是少库啊.我也遇到这样的问题,可惜我不知道加什么库.
楼主现在解决了吗?麻烦指点指点

论坛徽章:
0
7 [报告]
发表于 2006-06-02 00:26 |只看该作者

——缺少链接库

/tmp/cch0Ysyf.o(.text+0x1c): undefined reference to `olon'
/tmp/cch0Ysyf.o(.text+0x5c): undefined reference to `oopen'
/tmp/cch0Ysyf.o(.text+0x82): undefined reference to `ologof'
/tmp/cch0Ysyf.o(.text+0xa: undefined reference to `oparse'
/tmp/cch0Ysyf.o(.text+0xb6): undefined reference to `oci_error'
/tmp/cch0Ysyf.o(.text+0xc3): undefined reference to `oexec'
/tmp/cch0Ysyf.o(.text+0xd1): undefined reference to `oci_error'
/tmp/cch0Ysyf.o(.text+0xde): undefined reference to `oclose'
/tmp/cch0Ysyf.o(.text+0x101): undefined reference to `ologof'

——这说明没有相关的.o或.a文件显式地放入你的链接语句中
—— find $ORACLE_HOME -name "*.[oa]"
—— 可以用 nm 看这些库是否有你要的 ock_error 等函数目标代码的字符表。

[ 本帖最后由 bigmoyo 于 2006-6-2 13:41 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP