regex - MySQL function with parameters syntax error -


i'm trying convert query mysql function

set @v1 := ( select  count(id) count      article_category      (title "about usd")         or (title "about usd-%"  ,  title regexp '[0-9]$')            );  insert  `article_category`     (`title`,`meta_data`,`meta_description`)     values     ( if(@v1 <= 0, "about usd", concat("about usd","-",@v1) ),        "ddddd",       "ddddddd" ); 

this function should return next available name can use directly in insert statement:

create function `get_next_unique_name`(tabel nvarchar(255),naem nvarchar(255)) returns nvarchar(255)     deterministic begin  set @dd = select count(id) count tabel (title naem) or (title (naem+'-%') , title regexp '[0-9]$');  return (naem+'-'+@dd); end 

you must getting error on set @dd line.

you can't set values variable assigning statement.
have use select .... ... syntax set value variable.

there several other errors in code.
change them suggested below:

create      function `get_next_unique_name`( tabel nvarchar(255), naem nvarchar(255) )     returns nvarchar(255)     deterministic begin     declare _count int default 0;     select count(id) _count        tabel       ( title naem )          or ( title concat( naem, '-%' ) , title regexp '[0-9]$' );      return concat( naem, '-', _count ); end; 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -