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

mad*_*dia 2 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;$$
Run Code Online (Sandbox Code Playgroud)

我按照下面的代码在 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 );
Run Code Online (Sandbox Code Playgroud)

Rah*_*hul 5

这是您程序中的错误

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
Run Code Online (Sandbox Code Playgroud)

因为您已经author_id按照您发布的代码获得了

declare author_id int default 0;

select id into author_id from user_profile where user_name = in_author_name;
Run Code Online (Sandbox Code Playgroud)

你的实际插入应该是

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
Run Code Online (Sandbox Code Playgroud)