drop procedure if exists p_hello_world; create procedure p_hello_world() begin declare v_number int; ); ; set v_varchar = 'hello world'; -- for debug select v_number; select v_varchar; end; call p_hello_world(); drop procedure if exists p_hello_world
概述 变量在存储过程中会经常被使用,变量的使用方法是一个重要的知识点,特别是在定义条件这块比较重要. mysql版本:5.6 变量定义和赋值 #创建数据库 DROP DATABASE IF EXISTS Dpro; CREATE DATABASE Dpro CHARACTER SET utf8 ; USE Dpro; #创建部门表 DROP TABLE IF EXISTS Employee; CREATE TABLE Employee (id INT NOT NULL PRIMARY KEY C
exec函数,可以循环定义.赋值多个变量 exec ("temp%s=1"%1) 这段代码的意思是,让exec执行temp1=1.字符串里面的%s由‘1’代替了. 我们在外面再套一个循环就可以实现对多个变量的定义了. for i in range(10): exec ("temp%s=1"%i) 在这里,通过一个循环来生成10个变量,i的变化从0到9.用变量i替代%s,所以在每次循环里面,分别给temp0.temp1.temp2……赋值为1. 如果想要替换多
/* MySQL中的变量局部变量,用户变量,会话变量和全局变量. 用户变量不用定义,直接使用. 1.用户变量赋值 set @xxx = 值; 2.查询 select @xxx; 语法帮助: 过程保存在information_schema.routines表中 help create PROCEDURE help drop PROCEDURE help SET help select help WHILE help if statement help declare bug点: 不同数据库可以存在