zoukankan      html  css  js  c++  java
  • 简单使用游标插入数据

    --创建数据库

    create proc InsertStudent

    as

    --定义所需要的变量

    declare @SchoolID int
    declare @ClassID int
    declare @StudentID int
    declare @IDNumber int  --条件判断时需要

    begin

    --创建游标

    declare FeeInsertStudent cursor for 
    select stuID,SchID,ClasID from T_School 

    --打开游标

    open FeeInsertStudent 

    --从游标里取出数据给 变量 赋值

    fetch next from FeeInsertStudent into @SchoolID,@ClassID,@StudentID

    --判断有标的状态

    while @@FETCH_STATUS=0

    begin

    --为变量赋值

    set @IDNumber=(select count(*) from T_LeaveSchool where StudentID=@StudentID and SchoolID=@SchoolID and ClassId=@ClassID)
    if(@IDNumber=0)  --判断
    begin
    insert into T_LeaveSchool(StudentID,ClassID,SchoolID)
    values( @StudentID,@ClassID,@StudentID)
    end
    fetch  next from FeeInsertStudent into @SchoolID,@ClassID,@StudentID
    end
    close FeeInsertStudent         --关闭游标
    deallocate FeeInsertStudent                 --撤销游标


    end

  • 相关阅读:
    lists 函数整理
    orddict 练习
    github 的使用
    wxListCtrl 例子 二
    Erlang eunit
    Erlang 中 Tuple 使用 以及 List 模块意外
    Erlang Json
    模块和包
    Mysql作为zabbix数据库ibdata1文件太高解决
    用户管理和数据库安全
  • 原文地址:https://www.cnblogs.com/duanlinlin/p/3305476.html
Copyright © 2011-2022 走看看