Reputation: 341
Been trying to figure why this is not compiling and giving me an error. It has to be something simple. I have a SP that accepts five parameters, sets the description to empty string and the date_added to today. Want to call the sp and insert a row into the table.
here is my code:
delimiter //
create procedure insert_products
(
category_id_param int,
product_code_param varchar(10),
product_name_param varchar(255),
list_price_param decimal(10,2),
discount_percent_param decimal(10,2)
)
begin
declare description_var text;
declare date_added_var datetime;
--validate parameters
if list_price_param < 0 then
signal sqlstate '22003'
set message_text = 'List price must be positive number',
mysql_errno = 1264;
elseif discount_price_param < 0 then
signal sqlstate '22003'
set message_text = 'Discount percent cannot be negative',
mysql_errno = 1264;
end if;
--set variable
set description_var = '';
set date_added_var = now();
insert into products
values(default, category_id_param, product_code_param,
product_name_param,description_var, list_price_param,
discount_percent_param, date_added_var);
end//
delimiter ;
call insert_products(33, 100, 'jet ski', 25.66, .30);
Upvotes: 0
Views: 676
Reputation: 122002
Add white space after the --
in comments.
--validate parameters
should be like this:
-- validate parameters
More information about the comments - Comment Syntax.
Upvotes: 2
Reputation: 4211
Try to remove:
delimiter //
and
//
delimiter
also specify the columnNames of:
insert into products (column1,column2,column3,...)values()
Third option:
from
end//
To:
end;//
Upvotes: -1