MariaDB LOAD_FILE() Function
In MariaDB, the LOAD_FILE()
function reads a given file and returns the file contents as a string.
MariaDB LOAD_FILE()
Syntax
Here is the syntax of the MariaDB LOAD_FILE()
function:
LOAD_FILE(filepath)
Parameters
filepath
-
Required. The path to the file to read. You should specify a full path.
If you do not provide a parameter, MariaDB will report an error: ERROR 1582 (42000): Incorrect parameter count in the call to native function 'LOAD_FILE'
.
Return value
The MariaDB LOAD_FILE()
function returns a string which is the file content of the file specified by the parameter.
If the specified file cannot be found, or if there is no file access permission, the LOAD_FILE()
function will return NULL
.
If the argument is NULL
, the LOAD_FILE()
function will return NULL
.
MariaDB LOAD_FILE()
Examples
The following is the content of the text file d:\test.txt
:
Hello World
To read the contents of this file, use the following statement with the MariaDB LOAD_FILE()
function:
SELECT LOAD_FILE('d:\\test.txt');
Output:
+---------------------------+
| LOAD_FILE('d:\\test.txt') |
+---------------------------+
| Hello World |
+---------------------------+
Conclusion
The MariaDB LOAD_FILE()
function returns the contents of the file specified by the parameter as a string.