How to import table data in PL/SQL?

There are a few ways to import table data in PL/SQL.

  1. Use the INSERT statement to transfer data from one table to another by writing an INSERT INTO statement. For example:
  2. Insert data from one table into another table with specific columns.
  3. Specify the tables and columns to import in the SELECT statement, then insert them into the specified table.
  4. Using a PL/SQL block: You can write a PL/SQL block to handle data import operations. For example:
  5. DECLARE
    — Declare variables
    variable1 table_name.column1%TYPE;
    variable2 table_name.column2%TYPE;
    variable3 table_name.column3%TYPE;
    BEGIN
    — Fetch data
    SELECT column1, column2, column3
    INTO variable1, variable2, variable3
    FROM another_table;

    — Insert data
    INSERT INTO table_name (column1, column2, column3)
    VALUES (variable1, variable2, variable3);

    — Commit the transaction
    COMMIT;
    END;

  6. In a PL/SQL block, data is first queried from another table and stored in a variable, which is then inserted into a specified table using the INSERT INTO statement.
  7. You can use the SQLLoader tool provided by Oracle database to load data, by specifying the format and rules for importing the data using a control file. To run SQL*Loader, you can use the following command:
  8. sqlldr username/password control file path
  9. Specify the tables and data files to import in the control file, and define the format and rules of the data.

Here are several common ways to import data into tables in PL/SQL. Choose the appropriate method based on specific requirements to perform the data import operation.

bannerAds