简体   繁体   中英

bulk load UDT columns in Oracle

I have a table with the following structure:

create table my_table (
    id integer,
    point Point -- UDT made of two integers (x, y)
)

and i have a CSV file with the following data:

#id, point
1|(3, 5)
2|(7, 2)
3|(6, 2)

now i want to bulk load this CSV into my table, but i cant find any information about how to handle the UDT in Oracle sqlldr util. Is is possible to use the bulk load util when having UDT columns?

I don't know if sqlldr can do this, but personally I would use an external table.

Attach the file as an external table (the file must be on the database server), and then insert the contents of the external table into the destination table transforming the UDT into two values as you go. The following select from dual should help you with the translation:

select
  regexp_substr('(5, 678)', '[[:digit:]]+', 1, 1) x_point,
  regexp_substr('(5, 678)', '[[:digit:]]+', 1, 2) y_point
from dual;

UPDATE

In sqlldr, you can transform fields using standard SQL expressions:

LOAD DATA
  INFILE 'data.dat'
  BADFILE 'bad_orders.txt'
  APPEND
  INTO TABLE test_tab
  FIELDS TERMINATED BY "|"
  (  info,
     x_cord "regexp_substr(:x_cord, '[[:digit:]]+', 1, 1)",
  )

The control file above will extract the first digit in the fields like (3, 4), but I cannot find a way to extract the second digit - ie I am not sure if it is possible to have the same field in the input file inserted into two columns.

If external tables are not an option for you, I would suggest either (1) transform the file before loading, using sed, awk, Perl etc or (2) SQLLDR the file into a temporary table and then have a second process to trandform the data and insert into your final table. Another option is to look at how the file is generated - could you generate it so that the field you need to transform is repeated in two fields in the file, eg:

data|(1, 2)|(1, 2)

Maybe someone else will chip in with a way to get sqlldr to do what you want.

Solved the problem after more research, because Oracle SQL*Loader has this feature, and it is used by specifying a column object , the following was the solution:

LOAD DATA
INFILE *
INTO TABLE my_table
FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(
    id,
    point column object
    (
        x,
        y
    )
)
BEGINDATA
1,3,5
2,7,2
3,6,2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM