易截截图软件、单文件、免安装、纯绿色、仅160KB

mysql存储过程中参数的in,out,inout区别


MySQL存储过程的参数用在存储过程的定义,共有三种参数类型,IN,OUT,INOUT,形式如:
CREATE PROCEDURE([[IN |OUT |INOUT ] 参数名 数据类形...])
1、IN 输入参数:表示该参数的值必须在调用存储过程时指定,在存储过程中修改该参数的值不能被返回,为默认值
2、OUT 输出参数:该值可在存储过程内部被改变,并可返回
3、INOUT 输入输出参数:调用时指定,并且可被改变和返回
 
 
1、MySQL 存储过程参数(in)
MySQL 存储过程 “in” 参数:跟 C 语言的函数参数的值传递类似, MySQL 存储过程内部可能会修改此参数,但对 in 类型参数的修改,对调用者(caller)来说是不可见的(not visible)。
drop procedure if exists pr_param_in;
 
create procedure pr_param_in
(
   in id int -- in 类型的 MySQL 存储过程参数
)
begin
   if (id is not null) then
      set id = id + 1;
   end if;
 
   select id as id_inner;
end;
set @id = 10;
 
call pr_param_in(@id);
 
select @id as id_out;
mysql> call pr_param_in(@id);
+----------+
| id_inner |
+----------+
|       11 |
+----------+
 
mysql> select @id as id_out;
+--------+
| id_out |
+--------+
| 10     |
+--------+
可以看到:用户变量 @id 传入值为 10,执行存储过程后,在过程内部值为:11(id_inner),但外部变量值依旧为:10(id_out)。
2、MySQL 存储过程参数(out)
MySQL 存储过程 “out” 参数:从存储过程内部传值给调用者。在存储过程内部,该参数初始值为 null,无论调用者是否给存储过程参数设置值。
drop procedure if exists pr_param_out;
 
create procedure pr_param_out
(
   out id int
)
begin
   select id as id_inner_1;  -- id 初始值为 null
 
   if (id is not null) then
      set id = id + 1;
 
      select id as id_inner_2;
   else
      select 1 into id;
   end if;
 
   select id as id_inner_3;
end;
set


相关文档:

mysql 中的字符串连接 CONCAT(str1,str2,...)

返回来自于参数连结的字符串。如果任何参数是NULL,返回NULL。可以有超过2个的参数。一个数字参数被变换为等价的字符串形式。
mysql> select CONCAT('My', 'S', 'QL');
-> 'MySQL'
mysql> select CONCAT('My', NULL, 'QL');
-> NULL
mysql> select CONCAT(14.3);
-> '14.3'
如:update test set ......

MySQL小数位取整

//得分计算四舍五入
SELECT ROUND((SUM(getfeng)/SUM(totalfeng))*100) as feng from answerdata WHERE uid='151' AND targetid IS NOT NULL
1.ceil () /ceiling() 向上取整
   例: ceil(1.2) = 2
2.floor () 向下取整
    例: floor(1.2) = 1
3.round() 四舍五入
 &n ......

mysql的三种安装方式

安装的OS为Solaris10,mysql 版本是5.1.38
一、使用RPM包进行安装

    首先可以从安装光盘中或者到mysql的网站上下载对应版本的rpm包如下:
MySQL-server-community-5.1.38-0.rhel5.i386.rpm
MySQL-client-community-5.1.38-0.rhel5.i386.rpm
    接着我们可以使用rpm命 ......

MySQL命令

1. 连接mysql:
mysql -h 主机地址 -u 用户名 -p
2.退出mysql:exit
3. 修改密码:
mysqlbinmysqladmin -uroot -p(oldpassword) password newpassword
4.增加用户:
添加一个用户test1 密码为ABC;让他可以在任何主机上登录,并对所有数据库有查询、插入、修改、删除的权限。首先用以root用户连入
mysql,然后键入以下命 ......

mysql新增用户和登录


新增用户:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'你的远端ip' IDENTIFIED BY '你的密码' WITH GRANT OPTION;
如:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'10.10.19.220' IDENTIFIED BY '123456' WITH GRANT OPTION;
登录到新增的用户:(假如原授权机的IP为10.10.19.222)
mysql -uroot  -p123456&n ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号