#1136 - 对于mysql存储过程,列计数与第1行的值计数不匹配

时间:2014-05-29 12:01:30

标签: mysql stored-procedures

当我尝试调用以下sp代码时,它会给出上述错误。 参数的数量相等

drop procedure if exists add_post_with_name;
create procedure add_post_with_name(  in_author_name int ,in_title varchar(150),in_content text , in_html text, in_slug varchar(250),in_post_type varchar(50) , in_url tinyint)  
begin
    declare post_id int default 0;
    declare author_id int default 0;

    select id into author_id from user_profile where user_name = in_author_name;
    if ( author_id ) then
      insert into post (title,content,html,slug,post_type,url,author_id)
              values (in_title,in_content,in_html,in_slug,in_post_type,in_url);
      select id into post_id from post where id = last_insert_id();

      if ( in_post_type = 'SCHOLARSHIP' or in_post_type = 'JOB'
          or in_post_type = 'QUESTION' or in_post_type = 'BLOG' or in_post_type = 'SOCIAL BOOKMARK' ) then
          insert into post_hierarchy_rel (child_post_id) values (post_id);
      end if;
      select post_id;
    else
      select 0;
    end if;

end;$$

我正在使用下面的代码在phpmyadmin中进行调用...它抛出了上述错误。

SET @p0='temp'; 
SET @p1='asdddddddd'; 
SET @p2='aaaaaaaaaaaa'; 
SET @p3='aaaaaaaaaaaaa'; 
SET @p4='aaaaaaaaaa'; 
SET @p5='JOB'; 
SET @p6='1'; 

CALL `add_post_with_name`(@p0, @p1, @p2, @p3, @p4, @p5, @p6 );

2 个答案:

答案 0 :(得分:4)

以下是您的程序中的错误

insert into post (title,content,html,
slug,post_type,url,author_id) <-- here you have 7 columns
values (in_title,in_content,in_html,
in_slug,in_post_type,in_url); <-- only 6 values supplied

由于您已按照发布的代码获得author_id

declare author_id int default 0;

select id into author_id from user_profile where user_name = in_author_name;

您的实际插入应该是

insert into post (title,content,html,
slug,post_type,url,author_id)
values (in_title,in_content,in_html,
in_slug,in_post_type,in_url,author_id); <-- see author_id included as last value

答案 1 :(得分:0)

author_id

中缺少values

变化:

insert into post (title,content,html,slug,post_type,url,author_id)
              values (in_title,in_content,in_html,in_slug,in_post_type,in_url);

为:

   insert into post (title,content,html,slug,post_type,url,author_id)
                  values (in_title,in_content,in_html,in_slug,in_post_type,in_url, author_id);