博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
数据库存储过程
阅读量:7174 次
发布时间:2019-06-29

本文共 1898 字,大约阅读时间需要 6 分钟。

这个东西目前用的不多,但是很强大,性能很高,用python插入三百万数据非常慢,CPU还烧到90度,存储过程执行了存储语句之后,相当迅速

复杂的存储过程

存储过程:保存在MySQL上的一个别名 => 一坨SQL语句		别名()		用于替代程序员写SQL语句		方式一:数据库存储过程,程序调用			MySQL: 存储过程			程序:调用存储过程		方式二:程序直接写语句			MySQL:。。			程序:SQL语句		方式三:程序利用类和对象			MySQL:。。			程序:类和对象(SQL语句)		1. 简单			create procedure p1()			BEGIN				select * from student;				INSERT into teacher(tname) values("ct");			END			call p1()			cursor.callproc('p1')		2. 传参数(in,out,inout)			delimiter //			create procedure p2(				in n1 int,				in n2 int			)			BEGIN				select * from student where sid > n1;			END //			delimiter ;			call p2(12,2)			cursor.callproc('p2',(12,2))		3. 参数 out			delimiter //			create procedure p3(				in n1 int,				inout n2 int			)			BEGIN				set n2 = 123123;				select * from student where sid > n1;			END //			delimiter ;			set @v1 = 10;			call p2(12,@v1)			select @v1;			set @_p3_0 = 12			ser @_p3_1 = 2			call p3(@_p3_0,@_p3_1)			select @_p3_0,@_p3_1			cursor.callproc('p3',(12,2))			r1 = cursor.fetchall()			print(r1)			cursor.execute('select @_p3_0,@_p3_1')			r2 = cursor.fetchall()			print(r2)			=======> 特殊					a. 可传参: in   out   inout					b. pymysql							cursor.callproc('p3',(12,2))							r1 = cursor.fetchall()							print(r1)							cursor.execute('select @_p3_0,@_p3_1')							r2 = cursor.fetchall()							print(r2)		为什么有结果集又有out伪造的返回值?			delimiter //			create procedure p3(				in n1 int,				out n2 int  用于标识存储过程的执行结果  1,2			)			BEGIN				insert into vv(..)				insert into vv(..)				insert into vv(..)				insert into vv(..)				insert into vv(..)				insert into vv(..)			END //			delimiter ;

  

 这个就是我写的简单的插入数据库三百万条数据的存储过程

表中插入3百万行数据:delimiter //create procedure p10()begin	declare i int;	set i=1;	while i<=3000000 do		insert into helloxu(sid,sname,email,gender) values		(i,CONCAT("alex",i),CONCAT("fox",i),"man");		set i=i+1;	end while;end  //delimiter ;call p10()

  

 

转载于:https://www.cnblogs.com/adamans/articles/7569507.html

你可能感兴趣的文章
文件描述符的申请与回收
查看>>
C++ 模板类的参数推导
查看>>
Cview的派生类
查看>>
Android activity的生命周期
查看>>
HTML5+Css3-webkit-filter
查看>>
css border-bottom(指定下边线的样式、宽度及颜色)
查看>>
Spring框架
查看>>
Aspose.Cells.dll的用法
查看>>
P1352 没有上司的舞会
查看>>
Bzoj 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 深搜,bitset
查看>>
关于《淘宝技术这十年》
查看>>
System类
查看>>
某网站html的注释
查看>>
IOS异步获取数据并刷新界面dispatch_async的使用方法
查看>>
macos mojave 安装brew 出错总结
查看>>
HDU 1667 Nested Dolls
查看>>
当程序的后台代码无法调试的时候,检查三个地方
查看>>
SQL数据库类型
查看>>
XGPush集成(信鸽集成)demo
查看>>
结构化异常处理 读书笔记
查看>>