create procedure p10(in sex int) begin declare user_no varchar(100); declare user_pwd varchar(100); declare user_cursor cursor for select user_no,user_pwd from t_user where sex = sex; declare exit handler for not found close user_cursor; drop table if exists t_user_test; create table t_user_test( id int primary key auto_increment, user_no varchar(100) not null, user_pwd varchar(100) not null ); open user_cursor; while true do fetch user_cursor into user_no,user_pwd; insert into t_user_test(user_no,user_pwd) values(user_no,user_pwd); end while; end; 哪个地方有误
时间: 2023-08-10 14:03:09 浏览: 157
在该存储过程中,有一处错误:
```
declare user_cursor cursor for select user_no,user_pwd from t_user where sex = sex;
```
这里的 `sex = sex` 应该改为 `sex = in_sex`,以引用存储过程的输入参数。修改后的存储过程如下:
```
create procedure p10(in sex int)
begin
declare user_no varchar(100);
declare user_pwd varchar(100);
declare user_cursor cursor for select user_no,user_pwd from t_user where sex = in_sex;
declare exit handler for not found close user_cursor;
drop table if exists t_user_test;
create table t_user_test(
id int primary key auto_increment,
user_no varchar(100) not null,
user_pwd varchar(100) not null
);
open user_cursor;
while true do
fetch user_cursor into user_no,user_pwd;
insert into t_user_test(user_no,user_pwd) values(user_no,user_pwd);
end while;
end;
```
阅读全文