mysql - Unable to call a stored procedure -
i'm learning mysql stored procedures and, turns out, i'm not @ now. want create stored procedure selects columns different tables and, obviously, outputs result. have:
use `usertable159`; drop procedure if exists `getdatafor`; delimiter $$ use `usertable159`$$ create definer=`michael`@`%` procedure `getdatafor`(in country varchar(2), in asin varchar(20),in fc varchar(1)) begin set @sql = "select p.price, p.sku, p.fulfillment_channel, group_concat(es.excludedseller) excluded, r.excludenonfeatured "+country+"_products p left join ("+country+"_excludedsellers es, "+country+"_excluderules r) on p.seller_sku = es.seller_sku , p.seller_sku = r.seller_sku p.asin = '" + asin + "' , p.fulfillment_channel = " + fc + "; "; prepare stmt @sql; execute stmt; deallocate prepare stmt; end $$ delimiter ;
from errors expected when writing this... 1 surprising me:
error code: 1054. unknown column 'de' in 'field list'
this how call it:
call getdatafor(de, b000lnhb8a, 2);
the in parameter country
not in selected columns, how come?
i tried calling with
call getdatafor('de', 'b000lnhb8a', '2');
which results in
error code: 1064. have error in sql syntax; check manual corresponds mysql server version right syntax use near '2' @ line 1
you have several problems:
1) cannot concatenate strings +
in mysql. must use concat()
built-in function.
2) left join
syntax incorrect. should left join x on ... left join y on ...
.
3) must quote arguments. looks tried that. need that.
Comments
Post a Comment