求个大佬帮忙改下这段mysql的存储过程 一直报错 改了半天 40C

delimiter //
create procedure pp()
declare aa varchar(10);
declare bb varchar(10);
declare cc varchar(10);
declare dd varchar(10);
declare ee varchar(10);
declare ff varchar(10);
declare gg varchar(10);
declare ii int not null;
deciare c1 cursor

selecr * from
(select id id1,a from t3 where id=1) a,
(select id id2,b from t3 where id=2) b,
(select id id3,c from t3 where id=3) c,
(select id id4,d from t3 where id=4) d,
(select id id5,e from t3 where id=5) e,
(select id id6,f from t3 where id=6) f,
(select id id7,g from t3 where id=7) g;
open c1;
fetch next from c1 into aa,bb,cc,dd,ee,ff,gg,ii;
declare x int;
begin
for i in c1;
read_loop:Loop
select count(m) into x
from (
select i.id1 m
union
select i.id2
union
select i.id3
union
select i.id4
union
select i.id5
union
select i.id6
union
select i.id7
);
if
x/7>0.5 then
insert into t4 values(i.a,i.b,i.c,i.d,i.e,i.f,i.g);
commit;
end if;
leave read_loop;
end loop read_loop;
close c1;
end;
//
本意是用游标找到t3表的的笛卡尔积中每行数据每个字段id重复不超过一半的数据然后插入到t4表中 但是写出来一直报错 新手 一直改然后一直报错 哪位哥哥姐姐看下这个怎么修正能运行
帮帮忙 改完能用的话我可以再给20c 拜谢

0

2个回答

... 【deciare c1 cursor】改成declare ,【selecr * from 】改成select...另外问一下【for i in c1;】i是什么呀?;

0
weixin_42790422
铁头娃呀 大哥 我后来改了改 不报语法错误了 就是没有数据出来
大约一年之前 回复

CREATE PROCEDURE pp ()
BEGIN
DECLARE iid1 INT;

DECLARE iid2 INT;

DECLARE iid3 INT;

DECLARE iid4 INT;

DECLARE iid5 INT;

DECLARE iid6 INT;

DECLARE iid7 INT;

DECLARE a1 VARCHAR (10);

DECLARE b1 VARCHAR (10);

DECLARE c1 VARCHAR (10);

DECLARE d1 VARCHAR (10);

DECLARE e1 VARCHAR (10);

DECLARE f1 VARCHAR (10);

DECLARE g1 VARCHAR (10);
DECLARE x INT;
DECLARE cur_c CURSOR FOR SELECT
id1,
id2,
id3,
id4,
id5,
id6,
id7,
a,
b,
c,
d,
e,
f,
g
FROM
(SELECT id id1, a FROM t3) a,
(SELECT id id2, b FROM t3) b,
(SELECT id id3, c FROM t3) c,
(SELECT id id4, d FROM t3) d,
(SELECT id id5, e FROM t3) e,
(SELECT id id6, f FROM t3) f,
(SELECT id id7, g FROM t3) g;

OPEN cur_c;

read_loop :
LOOP

FETCH NEXT
FROM
cur_c INTO iid1,
iid2,
iid3,
iid4,
iid5,
iid6,
iid7,
a1,
b1,
c1,
d1,
e1,
f1,
g1;

SELECT
count(m) INTO x
FROM
(
SELECT
iid1 m
UNION
SELECT
iid2
UNION
SELECT
iid3
UNION
SELECT
iid4
UNION
SELECT
iid5
UNION
SELECT
iid6
UNION
SELECT
iid7
) r;

IF x / 7 > 0.5 THEN
INSERT INTO t4
VALUES
(t3.a, t3.b, t3.c,t3.d,t3.e,t3.f,t3.g);

COMMIT;

END
IF;

LEAVE read_loop;

END
LOOP
read_loop;

CLOSE cur_c;

END

这是我后来改的 改完之后不报错 然后运行完了没数据出来 大哥们帮忙看下哪里写的有问题啊


0
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!