Return the file size by using the LOAD_FILE function : Buildin Functions « Procedure Function « SQL / MySQL






Return the file size by using the LOAD_FILE function

  
mysql>
mysql> delimiter $$
mysql>
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>
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)

mysql>
mysql>

          
  








Related examples in the same category

1.Check MySQL version
2.Call buildin math function in your procedure
3.Use Build-in SUM function in a procedure
4.Using String functions in a user-defined function
5.An example of a LOOP: test(n) returns once again a string with n asterisks.