How to import CSV data using SQLPlus?

To import CSV data using SQL*Plus, you can follow these steps:

  1. Convert the CSV file into a format suitable for importing, such as converting it into a comma-separated values (CSV) file.
  2. Open the command line window and start SQL*Plus using the following command:
  3. Connect to the database using the specified username and password in SQLPlus.
  4. “username” refers to the database username, “password” is the password, and “database” is the database name.
  5. Create an external table in SQL*Plus command line that maps to the structure of a CSV file using the following command:
  6. Set up a table called external_table with specified columns and data types. The table is organized externally using the Oracle Loader type and is linked to a directory named directory_name. The data is accessed with parameters specifying that records are separated by new lines and fields are separated by commas, with missing field values represented as NULL. The location of the data is in a CSV file named csv_file.csv.
  7. In the above command, “external_table” is the name of the external table to be created, “column1, column2, etc.” are the names and data types of the columns in the table, “directory_name” is the name of the Oracle directory object that points to the directory storing the CSV files, and “csv_file.csv” is the name of the CSV file.
  8. Import the CSV data into the database table using the following command.
  9. Add all data from the external table into the destination table.
  10. In the above command, ‘destination_table’ is the name of the table where the CSV data will be imported.
  11. You can use the following command to verify if the data has been successfully imported:
  12. Retrieve all columns from the destination table.

The above are the general steps for importing CSV data using SQL*Plus. Please make sure to modify the table name, column names, directory name, and file name according to your actual situation.

bannerAds