I am new to MySQL Stored Procedure, in my first attempt I got the following issues,
Stored Procedure:
Delimiter $$
create procedure accountstatus
(
IN inmode varchar(27),
IN AccountStatus_id int,
IN AccountStatus varchar(255),
IN CreatedOn datetime,
IN CreatedBy varchar(255),
IN UpdatedOn datetime,
IN UpdatedBy varchar(255),
IN is_active bit)
Begin
if inmode = 'insert'
then
insert into accountstatus
(AccountStatus_id, Account_Status, CreatedOn, CreatedBy, UpdatedOn, UpdatedBy, is_active)
values
(AccountStatus_id, Account_Status, CreatedOn, CreatedBy, UpdatedOn, UpdatedBy, is_active);
end if;
/*update*/
if inmode = 'update'
then
update accountstatus acc
set
acc.AccountStatus_id = AccountStatus_id,
acc.Account_Status = Account_Status,
acc.CreatedOn = CreatedOn,
acc.CreatedBy = CreatedBy,
acc.UpdatedOn = UpdatedOn,
acc.UpdatedBy = UpdatedBy,
acc.is_active = is_active
where
acc.AccountStatus_id = AccountStatus_id;
end if;
/*delete*/
if inmode = 'delete'
then
update accountstatus acc
set
acc.AccountStatus_id = AccountStatus_id,
acc.is_active = 0
where
acc.AccountStatus_id = AccountStatus_id;
end if;
/*select*/
if inmode = 'select'
then
select * from accountstatus acc
where
acc.AccountStatus_id = AccountStatus_id;
end if;
end
When I execute these statements I got the following output:
STATEMENT
call accountstatus ('insert', 1, 'accepted', current_date(),'rathish', current_date(), 'raj', 1);
OUTPUT
call accountstatus ('insert', 8, 'accepted', current_date(),'rathish', current_date(), 'raj', 1)
1 row(s) affected
Similarly I inserted some values to this table, but when I tried to execute the following update statement, values in the Account_Status became null as shown below,
STATEMENT
call accountstatus ('update', 8, 'accepted', current_date(),'raj', current_date(), 'raj', 1);
OUTPUT
call accountstatus ('update', 8, 'accepted', current_date(),'raj', current_date(), 'raj', 1)
1 row(s) affected
But, when I execute the following query statement I got the unexpected output as follows,
- What is error in this procedure?
- Is there any other ways to implement this procedure?
- How it will effect the performance of the database?
Thanks in advance.