Mysql的存储过程的使用
在mysql中创建存储过程procedure并且用call语句来调用是基本功
CREATE table title( titleID int(11) PRIMARY KEY , title VARCHAR(100), subtitle varchar(100), edition TINYINT(4), publID int(11), catID int(11), langID int(11), year int(11), isbn varchar(20), comment varchar(255), ts timestamp, authors varchar(255) );
[SQL] INSERT INTO title VALUES (1,'Linux','Installation',5,1,57,2,2000,NULL,NULL,'2005-02-28 13:34:21','Michael'), (2,'Excel',NULL,NULL,2,3,NULL,2000,NULL,NULL,'2005-02-28 13:34:22','David'), (3,'XML',NULL,NULL,1,2,NULL,1997,NULL,NULL,'2005-02-28 13:34:22','Edwards'), (4,'PHP',NULL,NULL,3,6,NULL,2000,NULL,NULL,'2005-02-28 13:34:22','Tom'), (5,'MySQL','',0,3,34,NULL,2000,'','','2005-02-28 13:34:22','Paul'), (6,'Java',NULL,NULL,4,34,NULL,1999,NULL,NULL,'2005-02-28 13:34:22','Tim'); 受影响的行: 6 时间: 0.153s
[SQL] CREATE TABLE publishers ( publID int(11) NOT NULL auto_increment, publName varchar(60) collate latin1_german1_ci NOT NULL default '', ts timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, PRIMARY KEY (publID), KEY publName (publName) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_german1_ci; 受影响的行: 0 时间: 0.404s
[SQL]INSERT INTO publishers VALUES (1,'A','2004-12-02 18:36:58'), (2,'Apress','2004-12-02 18:36:58'), (3,'New Riders','2004-12-02 18:36:58'), (4,'O\'Reilly & Associates','2004-12-02 18:36:58'), (5,'Hanser','2004-12-02 18:36:58'); 受影响的行: 5 时间: 0.148s
存储过程创建时间
[SQL]create PROCEDURE get_title(in id int) BEGIN SELECT title,subtitle,publName from title,publishers where titleID=id and titles.publID = publishers.publID; END
[SQL]create PROCEDURE half(in a int,out b int) BEGIN set b=a/2; END 受影响的行: 0 时间: 0.001s
删除存储过程,发现写错了
[SQL]drop PROCEDURE get_title; 受影响的行: 0 时间: 0.006s
重新创建过
[SQL]create PROCEDURE get_title(IN id INT) BEGIN SELECT title, subtitle, publName FROM title, publishers WHERE titleID=id AND title.publID = publishers.publID; END 受影响的行: 0 时间: 0.001s
查询数据库中的存储过程
方法一:
select `name` from mysql.proc where db = 'your_db_name' and `type` = 'PROCEDURE'
方法二:
show procedure status;
查看存储过程或函数的创建代码
show create procedure proc_name;
show create function func_name;
查看一下触发器的创建代码
show CREATE PROCEDURE get_title;
调用用call get_title(1);