#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sqlca.h" EXEC SQL BEGIN DECLARE SECTION;
char *serverid="scott/123456@orcl";
int deptid;
char edname[];
char edloc[];
EXEC SQL END DECLARE SECTION; void main()
{
int ret=;
EXEC SQL connect:serverid ;
if(sqlca.sqlcode!=)
{
ret=sqlca.sqlcode;
printf("connect err :%d",ret);
system("pause");
}else
{
printf("connect ok!\r\n");
//赋值
deptid=;
strcpy(edname,"中国2");
strcpy(edloc,"广东");
//插入数据
printf("exec insert start !\n");
EXEC SQL insert into dept(DEPTNO,DNAME,LOC) values(:deptid,:edname,:edloc);
if(sqlca.sqlcode!=)
{
ret=sqlca.sqlcode;
printf("insert err :%d",ret);
system("pause");
return;
}
//注意每次执行DML操作都需要提交事务不断开连接
EXEC SQL commit;
getchar();
strcpy(edname,"80name");
strcpy(edloc,"guangdong");
//修改数据
EXEC SQL update dept set DNAME=:edname,LOC=:edloc where DEPTNO=:deptid;
//提交事务不断开连接
EXEC SQL commit;
printf("print any key delete !\n");
getchar();
//删除数据
EXEC SQL delete from dept where deptno=:deptid;
//提交事务断开连接
EXEC SQL commit release;
printf("Oracle closed !\r\n");
system("pause");
}
}
05-11 21:46