I am getting this error:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4
when i run followed code in phpmyadmin also appearing this error beside of second declare expression:
unrecognized statement type (near declare)
What can be cause of these error? (Phpmyadmin, version, etc)
create function fnc_generate_url(title_in varchar(250))
returns varchar(250)
begin
declare v_count int;
declare v_return varchar(250);
declare cr_count cursor
for
select count(1) from tbl_page where page_title like concat('%',title_in,'%');
open cr_count;
fetch cr_count into v_count;
close cr_count;
if v_count = 0 then
set v_return = replace(trim(title_in), ' ', '-');
else
set v_return = concat(replace(trim(title_in), ' ', '-'),'-',v_count);
end if;
return v_return;
end;