Oracle之使用proc增删改查

#define _CRT_SECURE_NO_WARNINGS
#include 
#include 
#include 
#include "sqlca.h"
#pragma comment(lib,"orasql11.lib")

//serverid 宿主变量
EXEC SQL	 BEGIN DECLARE SECTION;
	char * serverid = "scott/scott@orcl";
	int empno;//员工编号
	char ename[20];//员工名字
	int deptno;//部门编号
	int sal;//薪水
EXEC SQL END DECLARE SECTION;
void main()
{
	//嵌入式SQL必须以EXEC SQL开头
	EXEC SQL connect :serverid;
	//检测是否成功连接数据库
	if(sqlca.sqlcode != 0)
	{
		printf("sql connect error\n");
	}
	printf("connect success\n");

	//字段赋值
	empno = 7556;
	strcpy(ename,"LUCY");
	deptno = 10;

	//增加数据
	EXEC SQL insert into emp(empno, ename, deptno ) values (:empno, :ename, :deptno);
	EXEC SQL commit;
	printf("insert success\n");

	//删除数据
	EXEC SQL delete from emp where empno = 7556;
	EXEC SQL commit;
	printf("delete success\n");

	//修改数据
	sal = 1000;
	EXEC SQL update emp set sal = :sal where empno = 7556;
	EXEC SQL commit;
	printf("update success\n");

	//查询数据
	EXEC SQL select empno,ename,deptno,sal into :empno,:ename,:deptno,:sal from emp where empno = 7499;
	printf("%d\t%s\t%d\t%d\n",empno,ename,deptno,sal);

	//提交事务并断开连接
	EXEC SQL COMMIT RELEASE;

	system("pause");
}

你可能感兴趣的:(Oracle之使用proc增删改查)