存储过程

来源:互联网 发布:mysql数据库分页语句 编辑:程序博客网 时间:2024/05/16 14:33

              步骤:

  1、检验mysql版本

 select version()

 select @@ VERSION

2、存储过程是属于数据库的

 show databses;

 create database db1;

use dab1;

3、声明结束符

 delimiter //

 4、创建存储过程

  cretae procedere p1() select "hello,world!" //

 5、调用存储过程

 call p1() //

6、回复结束符

delimiter;

2、参数的应用

 in 输入形参参数的使用

  set @x=3;

 slect @x;

调用时必须有对应的实参(类型、数量)将信息带入到存储过程

create procedure p10(in para1 int) set @x=para1;

call p10(18);

select @x;

作用域

存储过程的局部变量:临时结果

语法格式  作用范围:从声明位置开始,到end结束

declare(声明) var_name type;

var_name 初值是null

set var_name=值

2)declare var_name type default 值;

create procedure p11()

begin

declare v1 int;

declare v2 int;

set v1=5;

set v2=7;

insert into t1 values(v1) ;

select * from t1;

end //

call p11(); //

 

原创粉丝点击