hy
i am trying to create a procedure with a cursor in order to fill with data 3 tables; the problem is that when i am calling the procedure i get the error 'Error Code: 1136. Column count doesn't match value count at row 1'; my procedure looks like this. any idea where the problems is ?
delimiter /
create procedure ggg () begin
declare a varchar(50);
declare b VARCHAR(30);
declare c VARCHAR(30);
declare d VARCHAR(30);
declare e VARCHAR(30);
declare gata int ;
DECLARE MyCursor CURSOR FOR
SELECT NumePacient,NumeMedic,PrenumeMedic,PrenumePacient,Cabinet
FROM `TABELA INTERMEDIARA`;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET gata = 1;
OPEN MyCursor;
myloop: LOOP
FETCH MyCursor INTO a,b,c,d,e;
if gata=1 then leave myloop;
else
insert into Pacienti select NumePacient,PrenumePacient from `TABELA INTERMEDIARA`
where NumePacient=a and PrenumePacient=c;
insert into Medici select NumeMedic,PrenumeMedic from `TABELA INTERMEDIARA`
where NumeMedic=c and PrenumeMedic=d;
insert into Cabinete select Cabinet from `TABELA INTERMEDIARA` where Cabinet = e;
end if;
end loop;
FETCH MyCursor
INTO a,b,c,d,e;
CLOSE MyCursor;
end /
delimiter ;
Table definitions:
CREATE TABLE Medici
(
idMedic int auto_increment not null primary key,
NumeMedic VARCHAR(50),
PrenumeMedic VARCHAR(50),
Statut ENUM('primar', 'specialist'),
Specialitate VARCHAR(50)
);
DROP TABLE IF EXISTS Pacienti;
CREATE TABLE Pacienti
(
IdPacient int auto_increment not null primary key,
NumePacient VARCHAR(50),
PrenumePacient VARCHAR(50)
);
DROP TABLE IF EXISTS Cabinete;
CREATE TABLE Cabinete
(
IdCabinet int auto_increment not null primary key,
DenCabinet VARCHAR(30)
);
Pacienti,MediciandCabinetito be sure, but in your threeINSERT ... SELECTstatements does the number ofSELECTed columns match the number of columns in theINSERTed table?INSERT ... SELECTto get the values that you appear already to have in the variablesa,b,c,dande?