当前位置:首页 > PHP教程 > PHP总结归纳

mysql写存储过程有关问题

mysql写存储过程问题 我想调用mysql存储过程建表,表名通过in参数来传进。 create procedure friendlist (in tname varchar(20)) begin set @sqlstr =concat('create table if not exists ', tname, '( userid int unsigned, phone varchar(20) not null, nam

mysql写存储过程问题
我想调用mysql存储过程建表,表名通过in参数来传进。
create procedure friendlist (in tname varchar(20))
begin
set @sqlstr =concat('create table if not exists ',
tname,
'(
userid int unsigned,
phone varchar(20) not null,
name varchar(30) not null,
birth int,
nick varchar(15),
impression varchar(50)
)engine=innodb default charset=utf8') ;
prepare stmt from @sqlstr;
execute stmt;
end;

在windows 的cmd下执行一直报错。 you have an error in your sql syntax; check the manual that corresponds to your mysql server version for the right syntax to use near
原来,在cmd下执行的mysql,其;相当于commit,所以会一直报这个错。
应更改语句结束符号,本实例将语句结束符更改为“//”。

于是:
delimiter //
create procedure friendlist (in tname varchar(20))
begin
set @sqlstr =concat('create table if not exists ',
tname,
'(
userid int unsigned,
phone varchar(20) not null,
name varchar(30) not null,
birth int,
nick varchar(15),
impression varchar(50)
)engine=innodb default charset=utf8') ;
prepare stmt from @sqlstr;
execute stmt;
end;
//.syntaxhighlighter{padding-top:20px;padding-bottom:20px;}

【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!