请问一个mysql存储过程的问题,定义老是失败,谢谢
mysql>desc_student;+-------+-------------+------+-----+---------+----------------+|Fi...
mysql> desc _student;
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| stuId | int(11) | NO | PRI | NULL | auto_increment |
| _name | varchar(50) | YES | | NULL | |
| _age | int(11) | YES | | NULL | |
+-------+-------------+------+-----+---------+----------------+
3 rows in set (0.05 sec)
create procedure insert_Student (_name varchar(50),_age int ,out _id int)
begin
insert into _student value(null,_name,_age);
select max(stuId) into _id from _student;
end;
提示ERROR 1327 (42000): Undeclared variable: _id错误,不知道为什么啊,_id不是我定义的输出参数吗
我用的mysql5.5,到网上找了几个列子,都是失败的,真是郁闷啊
改成一楼的那样还是提示同样的错误,而且默认的也应该就是输入参数才对啊 展开
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| stuId | int(11) | NO | PRI | NULL | auto_increment |
| _name | varchar(50) | YES | | NULL | |
| _age | int(11) | YES | | NULL | |
+-------+-------------+------+-----+---------+----------------+
3 rows in set (0.05 sec)
create procedure insert_Student (_name varchar(50),_age int ,out _id int)
begin
insert into _student value(null,_name,_age);
select max(stuId) into _id from _student;
end;
提示ERROR 1327 (42000): Undeclared variable: _id错误,不知道为什么啊,_id不是我定义的输出参数吗
我用的mysql5.5,到网上找了几个列子,都是失败的,真是郁闷啊
改成一楼的那样还是提示同样的错误,而且默认的也应该就是输入参数才对啊 展开
3个回答
展开全部
没问题啊
我在实际环境测试如下:
mysql> create table tb_name(stuId int auto_increment primary key,_name varchar(20),_age int);
Query OK, 0 rows affected (0.01 sec)
mysql> desc tb_name;
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| stuId | int(11) | NO | PRI | NULL | auto_increment |
| _name | varchar(20) | YES | | NULL | |
| _age | int(11) | YES | | NULL | |
+-------+-------------+------+-----+---------+----------------+
3 rows in set (0.02 sec)
mysql> delimiter //
mysql> create procedure insert_Student (_name varchar(50),_age int ,out _id int)
-> begin
-> insert into tb_name value(null,_name,_age);
-> select max(stuId) into _id from tb_name;
-> end;
-> //
Query OK, 0 rows affected (0.00 sec)
mysql> delimiter ;
mysql> call insert_Student('aa',10,@id);
Query OK, 0 rows affected (0.00 sec)
mysql> select @id;
+------+
| @id |
+------+
| 1 |
+------+
1 row in set (0.00 sec)
mysql> select * from tb_name;
+-------+-------+------+
| stuId | _name | _age |
+-------+-------+------+
| 1 | aa | 10 |
+-------+-------+------+
1 row in set (0.00 sec)
mysql>
我在实际环境测试如下:
mysql> create table tb_name(stuId int auto_increment primary key,_name varchar(20),_age int);
Query OK, 0 rows affected (0.01 sec)
mysql> desc tb_name;
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| stuId | int(11) | NO | PRI | NULL | auto_increment |
| _name | varchar(20) | YES | | NULL | |
| _age | int(11) | YES | | NULL | |
+-------+-------------+------+-----+---------+----------------+
3 rows in set (0.02 sec)
mysql> delimiter //
mysql> create procedure insert_Student (_name varchar(50),_age int ,out _id int)
-> begin
-> insert into tb_name value(null,_name,_age);
-> select max(stuId) into _id from tb_name;
-> end;
-> //
Query OK, 0 rows affected (0.00 sec)
mysql> delimiter ;
mysql> call insert_Student('aa',10,@id);
Query OK, 0 rows affected (0.00 sec)
mysql> select @id;
+------+
| @id |
+------+
| 1 |
+------+
1 row in set (0.00 sec)
mysql> select * from tb_name;
+-------+-------+------+
| stuId | _name | _age |
+-------+-------+------+
| 1 | aa | 10 |
+-------+-------+------+
1 row in set (0.00 sec)
mysql>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
create procedure insert_Student (_name varchar(50),_age int ,out _id int)
---create procedure insert_Student (in _name varchar(50),in _age int ,out _id int)
----------------------------------------------
喔,是不是结束符的原因
delimiter $$
create procedure insert_Student (in _name varchar(50),in _age int ,out _id int)
begin
insert into _student value(null,_name,_age);
select max(stuId) into _id from _student;
end $$
---create procedure insert_Student (in _name varchar(50),in _age int ,out _id int)
----------------------------------------------
喔,是不是结束符的原因
delimiter $$
create procedure insert_Student (in _name varchar(50),in _age int ,out _id int)
begin
insert into _student value(null,_name,_age);
select max(stuId) into _id from _student;
end $$
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
错误很简单啊,就是你把values写成value了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询