mysql 存储过程 批量导入数据_sql 利用存储过程批量导入数据

什么是

存储过程(stored procedure)是一组为了完成特定功能的sql语句集,是利用sql server所提供的transact-sql语言所编写的程序。经编译后存储在中。存储过程是数据库中的一个重要对象,用户通过指定存储过程的名字并给出参数(如果该存储过程带有参数)来执行它。存储过程是由流控制和sql语句书写的过程,这个过程经编译和优化后存储在数据库服务器中,存储过程可由应用程序通过一个调用来执行,而且允许用户声明变量 。同时,存储过程可以接收和输出参数、返回执行存储过程的状态值

存储过程语法

create procedure [拥有者.]存储过程名[;程序编号]   [(参数#1,…参数#1024)]   [with   {recompile | encryption | recompile, encryption}   ]   [for replication]

看一个简单的实例

create procedure order_tot_amt   @o_id int,   @p_tot int output   as   select @p_tot = sum(unitprice*quantity)   from orderdetails   where ordered=@o_id   go

下面来看一个利用存储过程批量导入数据实例

declare @mycounter int

set @mycounter = 0 /*设置变量*/

while (@mycounter < 2) /*设置循环次数*/

begin

waitfor delay '000:00:10' /*延迟时间10秒*/

insert into time_by_day

(time_id, the_date, the_year, month_of_year, quarter, day_of_month)

select top 1 time_id + 1 as time_id, the_date + 1 as the_date, year(the_date + 1)

as the_year, month(the_date + 1) as month_of_year, { fn quarter(the_date + 1)

} as quarter, day(the_date + 1) as day_of_month

from time_by_day

order by time_id desc

set @mycounter = @mycounter + 1

end

f68f2add0b68e4f9810432fce46917b7.png

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值