Mysql存储过程(http://dev.mysql.com/doc/refman/5.1/zh/index.html)
来源:互联网 发布:3cdaemon更改端口号 编辑:程序博客网 时间:2024/05/29 18:08
http://dev.mysql.com/doc/refman/5.1/zh/index.html
create procedure 'test'(param varchar(20))
begin
declare len int;
set len = LENGTH(param);
if(len>0) then
select * from st where id = param;
end if;
end
调用时 call test('');正常,call test('001');就会提示:
1267 -Illengal mix of collations(gbk_chinese_ci,IMPLICIT)and(latin1_swedish_ci,IMPLICIT)for operatopn '='
DELIMITER $$;
DROP PROCEDURE IF EXISTS sp_test$$
CREATE PROCEDURE sp_test()
BEGIN
declare cnt int;
select 1 from account where username='123' into cnt;
if cnt != 0 then
insert into account (username,passwd) values('123','123');
end if;
END$$
DELIMITER ;$$
mysql> delimiter //
mysql> CREATE PROCEDURE simpleproc (OUT param1 INT)
-> BEGIN
-> SELECT COUNT(*) INTO param1 FROM t;
-> END
-> //
Query OK, 0 rows affected (0.00 sec)
mysql> delimiter ;
mysql> CALL simpleproc(@a);
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT @a;
+------+
| @a |
+------+
| 3 |
+------+
1 row in set (0.00 sec)
当使用delimiter命令时,你应该避免使用反斜杠(‘/’)字符,因为那是MySQL的转义字符。
下列是一个例子,一个采用参数的函数使用一个SQL函数执行一个操作,并返回结果:
mysql> delimiter //
mysql> CREATE FUNCTION hello (s CHAR(20)) RETURNS CHAR(50)
-> RETURN CONCAT('Hello, ',s,'!');
-> //
Query OK, 0 rows affected (0.00 sec)
mysql> delimiter ;
mysql> SELECT hello('world');
+----------------+
| hello('world') |
+----------------+
| Hello, world! |
+----------------+
1 row in set (0.00 sec)
问题已经解决。答案如下:
mysql> PREPARE stmt1 FROM 'SELECT SQRT(POW(?,2) + POW(?,2)) AS hypotenuse';
mysql> SET @a = 3;
mysql> SET @b = 4;
mysql> EXECUTE stmt1 USING @a, @b;
+------------+
| hypotenuse |
+------------+
| 5 |
+------------+
(注意例子中的pow是个函数,?代表变量。当时被pow忽悠了。)
mysql> PREPARE stmt1 FROM 'SELECT SQRT(POW(?,2) + POW(?,2)) AS hypotenuse';
mysql> SET @a = 3;
mysql> SET @b = 4;
mysql> EXECUTE stmt1 USING @a, @b;
+------------+
| hypotenuse |
+------------+
| 5 |
+------------+
(注意例子中的pow是个函数,?代表变量。当时被pow忽悠了。)
- Mysql存储过程(http://dev.mysql.com/doc/refman/5.1/zh/index.html)
- MySQL API 中文连接 http://dev.mysql.com/doc/refman/5.1/zh/apis.html
- mysql 密码正确 被拒绝http://dev.mysql.com/doc/refman/5.1/en/access-denied.html
- MySQL的XML函数,摘自http://dev.mysql.com/tech-resources/articles/mysql-5.1-xml.html
- mysql 5.0存储过程学习总结http://www.ccvita.com/100.html
- http://taiyuan.ganchang.cn/info/index/14097081544494000006.html http://www.rayfile.com/zh-cn/files/f
- QT的英文教程:http://doc.trolltech.com/qq/index.html
- Node入门 http://nodebeginner.org/index-zh-cn.html
- MySQL存储引擎(转至http://www.cnblogs.com/gbyukg/archive/2011/11/09/2242271.html)
- MYSQL refman-5.5 read and organize
- MySQL存储过程学习(http://zhanshenlvbu.iteye.com/blog/1162203)
- http://zh.html.net/
- http://www.sysinternals.com/index.html
- http://www.jdon.com/index.html
- http://lib.closetou.com/diveintohtml5/index.html
- http://refactoring.com/catalog/index.html
- http://www.hao123.com/index.html
- http://www.debian.org/doc/manuals/debian-faq/ch-pkg_basics.zh-cn.html
- 覆水难收
- 实现windows下的动态域名解析服务
- 三国历史上最不该被埋没的十大人才!
- 嵌入式linux网络引导
- 信用卡对账单你读懂了吗?
- Mysql存储过程(http://dev.mysql.com/doc/refman/5.1/zh/index.html)
- [HP NX6320] 安装 windows2003 操作系统 全过程
- 使用Tomcat访问JSP页面时遇到的问题
- Delphi专区
- MySQL 数据库错误
- .net 2.0 访问Oracle
- DataFormatString--格式化字符串
- IT人不可不听的10个故事
- SIC图像压缩控件