您好,欢迎访问一九零五行业门户网

Mysql 自定义函数

mysql 自定义函数怎么用
create function `strip_tags`($str text) returns text begin declare $start, $end int default 1; loop set $start = locate(, $str, $start); if (!$end) then set $end = $start; end if; set $str = insert($str, $start, $end - $start + 1, ); end loop; end;
回复讨论(解决方案) select strip_tag('aaa
')


update tbl_name set html=strip_tag(html)


select strip_tag('aaa
')


update tbl_name set html=strip_tag(html)


mysql里执行下面代码报错
create function `strip_tags`($str text) returns text begin declare $start, $end int default 1; loop set $start = locate(, $str, $start); if (!$end) then set $end = $start; end if; set $str = insert($str, $start, $end - $start + 1, ); end loop; end;
不会错的,我刚刚测试了你的指令
你最好写到程序里 $sql =<<< 'sql'create function `strip_tags`($str text) returns text begin declare $start, $end int default 1; loop set $start = locate(, $str, $start); if (!$end) then set $end = $start; end if; set $str = insert($str, $start, $end - $start + 1, ); end loop; end;sql;mysql_query($sql) or die(mysql_error());
因为你使用了 php 的变量名表示,phpmyadmin 可能另做了处理
mysql_connect();mysql_select_db('test');$sql =<< ab)
select strip_tag('aaa
')


update tbl_name set html=strip_tag(html)


自定义函数可以存活多久?
永久,直到你删去他
永久,直到你删去他
我加了一句 drop function if exists `strip_tags`; 就报错了
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 'create function `strip_tags`($str text) returns text begin declare $start,' at line 2
$sql =<<< 'sql'drop function if exists `strip_tags`create function `strip_tags`($str text) returns textbegin declare $start, $end int default 1; loop set $start = locate(, $str, $start); if (!$end) then set $end = $start; end if; set $str = insert($str, $start, $end - $start + 1, ); end loop;end;sql;
按理说后面要加一个分号的
drop function if exists `strip_tags`;
但是mysql_query 只能执行一条sql语句,所以它把整个语句当成一条sql语句了,当成一条sql显然是不对的。
其它类似信息

推荐信息