บทเรียนกับ stored procedure บน mysql

stored procedure
stored procedure

บทเรียนกับ stored procedure บน mysql
1. ทดสอบกับ MySQL server
version 5.5.16 ใน thaiabc.com 8.0
2. เดิม start mysql ด้วย DOS>mysqld.exe –console
แต่พบปัญหาขณะ call procedure ว่า
ERROR 1436 (HY000): Thread stack overrun:  6892 bytes used of a 131072 byte stack, and 128000 bytes needed.  Use ‘mysqld –thread_stack=#’ to specify a bigger stack.
3. แก้ไขโดย start mysql ด้วย DOS>mysqld.exe –console –thread_stack=999999

4. สร้าง procedure
use test;
delimiter //
create procedure x01()
begin
select * from student;
end//
delimiter ;
grant execute on procedure test.x01 to ”@’localhost’;
call x01();

5. สร้าง function
create function addhead(s char(20))
returns char(50) deterministic
return concat(‘- ‘,s,’!’);
select addhead(sname) from student;

6. คำสั่งที่น่าสนใจ
show create procedure xxx;
drop procedure xxx;
show procedure status;
show function status;
help show;
show procedure status where Db = DATABASE() and type = ‘PROCEDURE’;
select * from mysql.proc;
select * from information_schema.routines;

7. web guides
http://devzonedd.designweb2you.com/viewthread.php?tid=82 ***
http://code.function.in.th/sqlserver/stored-procedure ***
http://www.mssqltips.com/sqlservertutorial/160/sql-server-stored-procedure/
http://msdn.microsoft.com/en-us/library/aa174792(v=sql.80).aspx
http://www.mysqltutorial.org/getting-started-with-mysql-stored-procedures.aspx
http://dev.mysql.com/doc/refman/5.1/en/stored-routines.html
http://php.net/manual/en/mysqli.quickstart.stored-procedures.php