我在向数据库中插入数据的时候想通过检查另外一个表格中的某行某列值是否为空,然后进行另外的一个操作. 写了半天一直都报错.... 我的代码如下(可能存在语法错误):create procedure InsertSelectPlayersProc(name varchar(20), job smallint(2), sex smallint(2),photo smallint(2))
begin
if((select Actor1 from ActorList) IS NULL) then 
insert into Players (Name,Sex,Photo) values(name,sex,photo);
         elseif((select Actor2 from ActorList) IS NULL) then 
insert into Players (Name,Job,Photo) values(name,job,photo);
         elseif((select Actor3 from ActorList) IS NULL) then 
insert into Players (Name,Job,Sex) values(name,job,sex);
end
麻烦帮忙解决....谢谢!

解决方案 »

  1.   

    select Actor1 from ActorList->select Actor1 into @ee from ActorList返回一个 OR 多个内容?
      

  2.   

    没看懂你的逻辑关系。首先一个问题,是把你的变量改一下名。
    create procedure InsertSelectPlayersProc(Vname varchar(20), Vjob smallint(2), Vsex smallint(2),Vphoto smallint(2))变量名和字段名相同时会有许多问题。
      

  3.   

    用触发器吧:create trigger tr_test before insert
    on ActorList
    for each row
    begin
    if new.Actor1 is null then 
    insert into Players (Name,Sex,Photo) values(name,sex,photo); 
    elseif new.Actor2 is null then 
    insert into Players (Name,Job,Photo) values(name,job,photo); 
    elseif new.Actor3 is null then 
    insert into Players (Name,Job,Sex) values(name,job,sex); 
    end if;
    end
      

  4.   

    create procedure InsertSelectPlayersProc(vname varchar(20), vjob smallint(2), vsex smallint(2),vphoto smallint(2))
    begin
    declare RoleType int(4);
    set RoleType = (select Actor1 from ActorList);
    if RoleType isnull then insert into Players (Name,Job,Sex,Photo) values(vname,vjob,vsex,vphoto);
    end怎么改?
      

  5.   


    create procedure InsertSelectPlayersProc(vname varchar(20), vjob smallint(2), vsex smallint(2),vphoto smallint(2)) 
    begin 
    declare RoleType int; 
    select Actor1 into RoleType from ActorList; 
    if RoleType is null then 
    insert into Players (Name,Job,Sex,Photo) values(vname,vjob,vsex,vphoto); 
    end if;
      

  6.   

    set RoleType = (select Actor1 from ActorList);
    你的这个 ActorList 表中就一条记录?