Best way to do multi-row insert in Oracle?

前端 未结 9 1397
悲&欢浪女
悲&欢浪女 2020-11-22 02:52

I\'m looking for a good way to perform multi-row inserts into an Oracle 9 database. The following works in MySQL but doesn\'t seem to be supported in Oracle.



        
9条回答
  •  [愿得一人]
    2020-11-22 03:25

    Use SQL*Loader. It takes a little setting up, but if this isn't a one off, its worth it.

    Create Table

    SQL> create table ldr_test (id number(10) primary key, description varchar2(20));
    Table created.
    SQL>
    

    Create CSV

    oracle-2% cat ldr_test.csv
    1,Apple
    2,Orange
    3,Pear
    oracle-2% 
    

    Create Loader Control File

    oracle-2% cat ldr_test.ctl 
    load data
    
     infile 'ldr_test.csv'
     into table ldr_test
     fields terminated by "," optionally enclosed by '"'              
     ( id, description )
    
    oracle-2% 
    

    Run SQL*Loader command

    oracle-2% sqlldr  control=ldr_test.ctl
    Password:
    
    SQL*Loader: Release 9.2.0.5.0 - Production on Wed Sep 3 12:26:46 2008
    
    Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
    
    Commit point reached - logical record count 3
    

    Confirm insert

    SQL> select * from ldr_test;
    
            ID DESCRIPTION
    ---------- --------------------
             1 Apple
             2 Orange
             3 Pear
    
    SQL>
    

    SQL*Loader has alot of options, and can take pretty much any text file as its input. You can even inline the data in your control file if you want.

    Here is a page with some more details -> SQL*Loader

提交回复
热议问题