#1136

系统教程 行业动态 更新时间:2024-06-14 16:57:17
#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 value

Here 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 supplied

Since 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

更多推荐

本文发布于:2023-04-12 20:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/61939a66ac13c1a04f1545b407ddb7a4.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!