INFILE
INFILE in SQL is used to read data from a text file. It is often utilized in the LOAD DATA INFILE statement for inserting multiple rows of data into a table from the file. The text file for INFILE is typically located on the server host and should be readable by the server.
Example
Output
Explanation
The LOAD DATA INFILE
statement in MySQL is used to read rows from a text file into a corresponding table in the database. In the example code, the ‘data.txt’ file is used as the data source and the data is loaded into the my_table
table in the database. The output signifies that the query was successfully executed and that 3 rows of data were affected (i.e., inserted into the table) without any warnings or errors.
Example
Output
Explanation
This script uses the UTL_FILE package to read a file (employees.txt in the MY_DIRECTORY directory). Each record in the file is retrieved with a call to the UTL_FILE.GET_LINE function, which reads a line from the file into a string variable. The individual fields within the record are then identified by using the SUBSTR function and converted (if necessary) by using the TO_NUMBER function, and then the fields are inserted into the employees table.