简体   繁体   中英

Error Code 1241 - Operand should contain 1 column(s)

I was creating a procedure and I came across this. Does anyone know how to solve this?

delimiter $$
create procedure sp_cadastraAluno(
in nome varchar(150),
in chamada varchar(3),
in data date, 
in ra varchar(12),
in turma varchar(50),
in cpf varchar(14))
begin
    declare x int;
    set x = (select * from tb_coordenador inner join tb_professor
    on tb_coordenador.cd_coord = tb_professor.cd_coord
    inner join prof_turma on
    tb_professor.cd_prof = prof_turma.cd_prof
    inner join tb_turma on
    prof_turma.cd_turma = tb_turma.cd_turma 
    inner join tb_aluno on
    tb_turma.cd_turma = tb_aluno.cd_turma where nm_turma = turma and tb_professor.cd_cpf = cpf);

    insert into tb_aluno(nm_aluno, cd_chamada, dt_nascimento, cd_ra, cd_turma) values
    (nome, chamada, data, ra, x);
end $$

I need to insert in tb_aluno and for this, I need to pull the code already inserted in tb_turma , but this error appears.

You can't set variable 'x' with multiple columns. try removing select * and replace with the column which you need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM