Sample Header Ad - 728x90

Repopulating Oracle tables using data from Excel/CSV file

2 votes
3 answers
4051 views
I'm developing a Java EE application that utilizes Hibernate/JPA. Some of the data I want to use comes from another Business unit's spreadsheet that I need to periodically (re)load into 5 Oracle tables, overwriting any existing data. I'm using a shell script that kicks off 5 sql*loader control files, where each control file specifies filler fields to skip because the excel file is not normalized. OPTIONS(skip=2) load data REPLACE --######################################### into table TABLE_NAME fields terminated by "," optionally enclosed by '"' TRAILING NULLCOLS ( ACCOUNT_ID , REST_STOP_ID , DESCRIPTION FILLER , GROUP FILLER , FUNCTION , JOB_ID "substr(:JOB_ID, 0, INSTR(:JOB_ID,' - ',1))", etc... First time import of this data into empty tables using SQL*Loader and a csv file from this spreadsheet works fine. But then any subsequent run sql*loader fails because either control file option: when using REPLACE: SQL*Loader-926: OCI error while executing delete/truncate (due to REPLACE/TRUNCATE keyword) **ORA-02292:** integrity constraint (SCHEMA.FK5BA979794B0A176A) violated - child record found when using TRUNCATE: SQL*Loader-926: OCI error while executing delete/truncate (due to REPLACE/TRUNCATE keyword) **ORA-02266:** unique/primary keys in table referenced by enabled foreign keys I've also tried reordering which the tables are populated but no luck. I've also tried disabling constraints ALTER TABLE TABLE_NAME DISABLE CONSTRAINT SYS_C0090398 ORA-02297: cannot disable constraint (SCHEMA.SYS_C0090398) - dependencies exist (0 rows affected) My work around so far is to drop all the tables restart my application and have Hibernate recreate my 5 tables and then run my sql*loader script. Right now I'm in development so not a big deal. But when we go to production, I can't keep restarting and creating tables. Actually when I go to production, I'll create the tables outside of hibernate but right now I have the persistence option hibernate.hbm2ddl.auto set to update. I'm looking for an elegant (semi)automatic solution to periodically repopulate these 5 tables with data provided to me in the csv/Excel file.
Asked by jeff (133 rep)
Sep 8, 2014, 03:20 PM
Last activity: Aug 8, 2016, 04:07 PM