zoukankan      html  css  js  c++  java
  • 数据库 proc编程三

    #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[32];
        char edloc[32];
    EXEC SQL END DECLARE SECTION;
    
    void main()
    {
        int ret=0;
        EXEC SQL connect:serverid ;
        if(sqlca.sqlcode!=0)
        {
            ret=sqlca.sqlcode;
            printf("connect err :%d",ret);
            system("pause");
        }else
        {
            printf("connect ok!
    ");
            //赋值
            deptid=97;
            strcpy(edname,"中国2");
            strcpy(edloc,"广东");
            //插入数据
            printf("exec insert start !
    ");
            EXEC SQL insert into dept(DEPTNO,DNAME,LOC) values(:deptid,:edname,:edloc);
            if(sqlca.sqlcode!=0)
            {
                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 !
    ");
            getchar();
            //删除数据
            EXEC SQL delete from dept where deptno=:deptid;
            //提交事务断开连接
            EXEC SQL commit release;
            printf("Oracle closed !
    ");
            system("pause");
        }
    }
  • 相关阅读:
    Arrays类总结
    多维数组
    数组
    写一个计算器,要求实现加减乘除功能,能够循环接收收据,通过用户交互实现
    递归
    方法
    函数
    流程控制
    mysql笔记(连接与子查询部分)
    ubuntu下mysql的常用命令
  • 原文地址:https://www.cnblogs.com/zhanggaofeng/p/6278185.html
Copyright © 2011-2022 走看看