请各位高手帮忙看看一下存储过程
create procedure p4(in p_id int,out name varchar(255),out age int)
begin 
declare tmp_name varchar(255);
declare tmp_age int;
select name into tmp_name from user where id = p_id;
if tmp_name is not NULL then
set name = tmp_name;
select age into tmp_age from user where id = p_id;
if tmp_name is not NULL then
set age = tmp_age;
end if;
end;
始终报错:在declare附近有语法错误,这个是什么原因呢,错在什么地方!

解决方案 »

  1.   

    DELIMITER $$
    CREATE PROCEDURE p4(IN p_id INT,OUT `name` VARCHAR(255),OUT age INT)
    BEGIN  
     DECLARE tmp_name VARCHAR(255);
     DECLARE tmp_age INT;
     SELECT `name` INTO tmp_name FROM `user` WHERE id = p_id;
     IF tmp_name IS NOT NULL THEN
     SET NAME = tmp_name;
     SELECT age INTO tmp_age FROM `user` WHERE id = p_id;
     END IF;
     IF tmp_name IS NOT NULL THEN
     SET age = tmp_age;
     END IF;
    END$$
    DELIMITER ;
      

  2.   

    if tmp_name is not NULL then
    set name = tmp_name;
    select age into tmp_age from user where id = p_id;
    if tmp_name is not NULL then怎么两个if是同样的条件