How to insert data directly from Excel to Oracle Database

前端 未结 5 905
无人共我
无人共我 2021-01-03 16:32

I would like to know how to insert data from Excel to Oracle meaning lets say i have a worksheet full of data and i want to insert them all into Oracle database.

5条回答
  •  死守一世寂寞
    2021-01-03 16:51

    You can use sql loader, but if you want a more robust solution (especially if the data will be modified directly in the spreadsheet) then look into external tables in Oracle. You can build a database table directly from the spreadsheet, the code looks like this:

    CREATE TABLE YOUR_SCHEMA.YOUR_TABLE
    (
      ACCT_NO                   VARCHAR2(15 BYTE),
      PRODUCT_TYPE              VARCHAR2(50 BYTE),
      ORGINATION_DATE           VARCHAR2(20 BYTE),
      MATURITY_DATE             VARCHAR2(20 BYTE),
      FIXED_PERIOD_START_DATE   VARCHAR2(30 BYTE),
      FIXED_PERIOD_END_DATE     VARCHAR2(30 BYTE),
      ORIGINAL_LOAN_AMOUNT      NUMBER,
      CURRENT_BALANCE           NUMBER
    )
    ORGANIZATION EXTERNAL
      (  TYPE ORACLE_LOADER
         DEFAULT DIRECTORY YOUR_DIRECTORY
         ACCESS PARAMETERS 
           ( RECORDS DELIMITED  BY NEWLINE
             LOGFILE YOUR_DIRECTORY:'your_log.log'
             BADFILE YOUR_DIRECTORY:'your_bad.bad'
             FIELDS TERMINATED BY ','
             MISSING FIELD VALUES ARE NULL )
         LOCATION (YOUR_DIRECTORY:'your_file.csv')
      )
    

    Note that anything with the word "your" in it above must be changed to whatever you want to name your files and directories. Also note that "YOUR_DIRECTORY" is an actual database object you must create:

    CREATE OR REPLACE DIRECTORY YOUR_DIRECTORY AS 'C:\workspaces\test\XL2ExternalTables'
    

提交回复
热议问题