分享一个mysql函数的例子,学习load_file的用法。
代码:
mysql> delimiter $$ mysql> CREATE PROCEDURE filesize(in_file_name VARCHAR(128)) -> -> BEGIN -> DECLARE mytext TEXT; -> SET mytext=LOAD_FILE(in_file_name); -> SELECT in_file_name||' contains '||length(mytext)||' bytes' -> AS output; -> END$$ Query OK, 0 rows affected (0.00 sec) mysql> delimiter ; mysql> call filesize("a.txt"); +--------+ | output | +--------+ | NULL | +--------+ 1 row in set (0.00 sec) Query OK, 0 rows affected, 2 warnings (0.00 sec) mysql> drop procedure filesize; Query OK, 0 rows affected (0.00 sec)