时间:2021-07-01 10:21:17 帮助过:25人阅读
3.查询
a.Navicat for mysql
set @m = 15; #设定参数 set @n = 10; call proc_p1(1,@m,@n); #执行存储过程 SELECT @m #查询参数
b.python 不清楚
import pymysql
#创建连接
conn = pymysql.connect(host=‘127.0.0.1‘,port=3306,user=‘root‘,password=‘Www123...‘,db="6.27db")
#创建游标
cursor = conn.cursor(cursor=pymysql.cursors.DictCursor)
cursor.callproc(‘proc_p1‘,(1,2,3))
ret = cursor.execute("select @_proc_p1_0,@_proc_p1_1,@_proc_p1_2")
result = cursor.fetchone()
conn.commit()
cursor.close()
conn.close()
print(ret,result,)
三、触发器
1.介绍:
对某个表进行操作(增、删、改)的之前和之后,会使另一个表也随之发生改变;
2.创建
delimiter $ #设置终止符号
drop trigger if EXISTS tri_brfore_inset_tb1 $ #判断是否已经存在
"""
# 设置插入前机制
1.tri_brfore_inset_tb1 取一个名字;
2.before 说明是操作前还是操作后;
3.insert 说明是 插入还是删除,显然这个例子是插入;
4. no tb1 说明 只有tb1变 才会发生变化;
5.began 这里面是说明 如果tb1 变了 指明另一个表也跟着变及要变什么;
"""
CREATE TRIGGER tri_brfore_inset_tb1 BEFORE INSERT ON tb1 FOR EACH ROW
BEGIN
INSERT INTO tb2 (favorate)
VALUES
(new.name);
END $ #对应的是begin $ 表示终止了
delimiter ; #恢复了终止符号为;
3.其它
a.nwe 可以指定跟随者变的值是主人插入的最新值;
b.old 可以指定跟随者变的值是主人刚删除的值;
四、函数
创建函数
delimiter \\ # 。。 drop function if exists f1\\ #。。 create function f1 (n int, m int) returns int #创建函数 设定形参,及返回值的类型 begin declare num int ; set num = n + m ; return num ; #指定返回值 enddelimiter ;
执行函数
select f1(1,2) 即可
五、内置函数
。。。
六、事物
1.是什么
答: 功能与python中的try 函数一样; 当发生错误时不执行。
2.创建
delimiter \create procedure p1( out p_return_code tinyint ) begin declare exit handler for sqlexception begin -- error set p_return_code = 1; rollback; end; declare exit handler for sqlwarning begin -- warning set p_return_code = 2; rollback; end; # start transaction; update tb1 set telephone = telephone + 5 where `name`= ‘coob1‘; update tb2 set favorate = favorate - 5 where nid<100; commit; -- success set p_return_code = 0; end\delimiter ;示例
3.在py_mysql中 pymysql模块中已经默认执行失误了,当sql语句出现错误时,自动报错。
七、mysql 动态语句
mysql小结篇2(17.6.27)
标签:ica 另一个 重写 font creat print and nec phone