开发者

Error in stored procedure - column count does not match value

I've created a stored procedure:

DELIMITER $$
DROP PROCEDURE IF EXISTS `zero`.`sp_for_insert_into_account_db`$$
CREATE PROCEDURE `zero`.`sp_for_insert_into_account_db` (usr_key char(6),usr_name varchar(15),usr_password varchar(15),OUT output_message INT)

BEGIN

DECLARE no_of_row INT;    
SELECT COUNT(*) INTO no_of_row from account_db;  
IF no_of_row < 4 THEN

    SET @s = CONCAT('insert into account_db (USR_KEY,USR_NAME,USR_PWD) VALUES (',usr_key,usr_name,usr_password,')');

    PREPARE stmt FROM @s;  
    EXECUTE stmt;    
    DEALLOCATE PREPARE stmt;    
    SET output_message=1;    
ELSE    
    SET output_message=0;       
END IF;
END$$

DELIMITER ;

I'm calli开发者_运维问答ng it with query

 call sp_for_insert_into_account_db('a','b','c',@output_ message);

The error is like:

Column count does not match value...

I'm passing 4 arguments...

Why is this error occurring?

I've already checked with this syntax (by default parameter is IN type)

sp_for_insert_into_account_db(IN usr_key char(6), 
                              IN usr_name varchar(15), 
                              IN usr_password varchar(15),
                              OUT output_message INT)


Problem is also here:

SET @s = CONCAT('insert into account_db (USR_KEY,USR_NAME,USR_PWD) VALUES (',usr_key,usr_name,usr_password,')');

You are trying to insert 3 values and the concatenation returns 1

use this instead:

SET @s = CONCAT('insert into account_db (USR_KEY,USR_NAME,USR_PWD) VALUES (\'',usr_key,'\',\'',usr_name,'\',\'',usr_password,'\')');


Not entirely sure why you're using prepared statements/dynamic sql when you dont need to ?? See the following example which i've cleaned up for you a little:

drop procedure if exists sp_for_insert_into_account_db;

delimiter #

create procedure sp_for_insert_into_account_db 
(
in p_usr_key char(6),
in p_usr_name varchar(15),
in p_usr_pwd varchar(15),
out p_output_message tinyint unsigned
)
begin

declare v_no_of_row int unsigned default 0;

set p_output_message=0;

select count(*) into v_no_of_row from account_db;

if v_no_of_row < 4  then
    insert into account_db(usr_key, usr_name, usr_pwd) values (p_usr_key, p_usr_name, p_usr_pwd);
    set p_output_message = 1;
end if;

end#

delimiter ;

call sp_for_insert_into_account_db (...);

EDIT

are you a COBOL PROGRAMMER FROM THE 1970'S AND IS THAT WHY YOU HAVE TO USE CAPS ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜