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");
        }
    }
  • 相关阅读:
    118. 杨辉三角
    1054. 距离相等的条形码
    面试题 02.01. 移除重复节点
    289. 生命游戏
    KONGA下的HAMC插件功能 --JAVA代码实现
    JPA
    Spring Cloud概述
    Spring框架分为哪七大模块,各模块的主要功能作用是什么
    ActiveMQ
    新手也能看懂,消息队列其实很简单
  • 原文地址:https://www.cnblogs.com/zhanggaofeng/p/6278185.html
Copyright © 2011-2022 走看看