oci 执行sql问题。

oldearth 2003-05-08 10:40:48

void insertRecord()
{
char insert[255] = "INSERT INTO emp(empno, ename, job, sal, deptno) VALUES (";

text *ename, *job,*empno, *sal, *deptno;
static sword sql_function;

ename = (text *) malloc((int)sizeof(sword) + 2);
job = (text *) malloc((int)sizeof(sword) + 2);
empno = (text *) malloc((int)sizeof(sword) + 2);
deptno = (text *) malloc((int)sizeof(sword) + 2);

//
printf("\nenter user name: ");
gets((char*)ename);

printf("\nenter job: ");
gets((char *) job);

printf("\nenter deptno: ");
gets((char*)deptno);

printf("\nenter empno: ");
gets((char*)empno);

printf("\nenter sal: ");
gets((char*)sal);

printf("\nenter complete please wait commit\n");

//执行sql语句
// :empno, :ename, :job, :sal, :deptno)

strcat((char*)insert,empno);

strcat((char*)insert,",'");
strcat((char*)insert,ename);
strcat((char*)insert,"'");

strcat((char*)insert,",'");
strcat((char*)insert,job);
strcat((char*)insert,"'");

strcat((char*)insert,",");
strcat((char*)insert,sal);

strcat((char*)insert,",");
strcat((char*)insert,deptno);

strcat((char*)insert,");");
printf("%s",insert);

if (oparse(&cda, (text *) insert, (sb4) -1,
(sword) 0, (ub4) 2))
{
oci_error(&cda);
}

if(oexec(&cda)&& cda.rc != 1)
{
printf("\nexecute the insert error.");
}
//提交
if(ocom(&lda))
{
printf("\ncommit error!");
}

}

检查sql 语句时出错。
打印出来的sql 在sql plus 里可以正确执行。
...全文
70 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
oldearth 2003-05-08
  • 打赏
  • 举报
回复
高人。
谢谢。
w_tsinghua 2003-05-08
  • 打赏
  • 举报
回复
up
Lastdrop 2003-05-08
  • 打赏
  • 举报
回复
把sql语句最后的;去掉
strcat((char*)insert,");");
改为
strcat((char*)insert,")");

3,499

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 高级技术相关讨论专区
社区管理员
  • 高级技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧