Joe Fatalis
Joe Fatalis

Reputation: 21

Mysql column count doesn't Match value count (but it does!)

I am running the following procedure in mysql:

create procedure addSavingAccount(id int(10), account_number varchar(10))
begin
insert into saving values(id,'savings', account_number, 0);
end //

However, when I try to call it, it gives me this error:

mysql> call addSavingAccount(103, 'B505');
ERROR 1136 (21S01): Column count doesn't match value count at row 1

I checked on anything that could be linked to it, including triggers. But everything seems like it should be working. Here is my list of triggers:

create trigger balance_change_saving after update on saving for each row
begin 
if old.balance != new.balance
then

insert into balance_update_history values(null, 'saving', new.account_number, old.balance, new.balance,
                                            (SELECT NOW()), (select USER()));
end if;
end//

create trigger balance_insert_saving after insert on saving for each row
begin
insert into balance_update_history values(null, 'saving', new.account_number, 0, new.balance, (select now()), 
                                            (select user())); 
end //


create trigger balance_delete_saving after delete on saving for each row
begin
insert into balance_update_history values(null, null, null, old.balance, null,
                                        (SELECT NOW()), (select USER()));
end //

And here is where I define the table:

create table if not exists saving(account_number varchar(10) , customer_id int(10), balance decimal(8,2), primary key(account_number));

I'd just really like to to figure this out.

Upvotes: 0

Views: 724

Answers (1)

Paul T.
Paul T.

Reputation: 4907

There are three columns based on your table create statement, not four. (what is the last 0 in that insert?)

Also, in the procedure, it appears that your insert values are out-of-order relative to the table creation order? So you can either rearrange the insert values to match the table, OR specify the columns with the insert.

Upvotes: 0

Related Questions