#1136 - 对于mysql存储过程,列计数与第1行的值计数不匹配(#1136 - Column count doesn't match value count at row 1 for mysql stored procedure)
当我试图调用以下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 );when I am trying to call the following sp code, it giving the above error. The number of argument is equal
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;$$I am making the call in phpmyadmin as per the below code ...Its throwing the above error.
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 );最满意答案
这是您程序中的错误
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 valueHere is the error in your procedure
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 suppliedSince you are already getting author_id per your posted code
declare author_id int default 0; select id into author_id from user_profile where user_name = in_author_name;Your actual insert should then be
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更多推荐
发布评论