Home » RDBMS Server » Server Utilities » SQL*Loader BAD FILE
SQL*Loader BAD FILE [message #70629] Tue, 09 July 2002 06:37 Go to next message
meena
Messages: 36
Registered: December 2000
Member
Hi All,

I have a table with a primary key constraint. I'm using SQL*Loader to load data into this table from an ASCII file.

My problem is that, if the rows violating the primary key constraints are all in the beginning of the ASCII file, then the .bad file is created correctly. Otherwise even good rows are rejected and sent to the .bad file. I need the .bad file to have just the rows violating the constraints so that these rows can be updated later.

Any ideas?
Thanks,
Meena
Re: SQL*Loader BAD FILE [message #70632 is a reply to message #70629] Tue, 09 July 2002 10:42 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10708
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
i cant really analyze the situation.
Anyhow this workaround may be helpful for you.
It has always worked for me, when loading tables with constraints.
1. the table to be loaded is DEPT
	create table dept
		(deptno char(4) primary key check (DEPTNO <  22), 
		 dname char(20), 
		 loc char(20)); 

2. create an exceptions table to hold the BAD data.

	create table exception_table
		     (row_id rowid,
		      owner varchar2(30),
		      table_name varchar2(30),
		      constraint varchar2(30))

3. the control file is  something like

LOAD DATA 
   INFILE * 
   TRUNCATE 
   INTO TABLE DEPT 
   REENABLE DISABLED_CONSTRAINTS EXCEPTIONS EXCEPTION_TABLE 
   FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' 
   (DEPTNO , 
   DNAME, 
   LOC) 
   BEGINDATA 
   12,RESEARCH,"BOSTN" 
   10,"ACCOUNTING",CLEVELAND 
   11,"ART",SALEM 
   13,FINANCE,"BOSTON" 
   21,"SALES",PHILA. 
   22,"SALES",ROCHESTER 
   42,"INT'L","SAN FRAN" 

4. oracle:->sqlldr userid=mag/mag@RDtest control=DEPT.CTL direct=y

   SQL*Loader: Release 8.1.6.0.0 - Production on Tue Jul 9 14:18:45 2002

   (c) Copyright 1999 Oracle Corporation.  All rights reserved.

   Load completed - logical record count 7.                             

5. SQL> select * from dept;

DEPT DNAME                LOC
---- -------------------- --------------------
12   RESEARCH             BOSTN
10   ACCOUNTING           CLEVELAND 

11   ART                  SALEM 

13   FINANCE              BOSTON
21   SALES                PHILA. 

22   SALES                ROCHESTER 

42   INT'L                SAN FRAN

SQL> select * from exception_table;

ROW_ID             OWNER      TABLE_NAME CONSTRAINT
------------------ ---------- ---------- ------------------------------
AAAFj+AABAAAH/SAAF MAG        DEPT       SYS_C001489
AAAFj+AABAAAH/SAAG MAG        DEPT       SYS_C001489

6. check the constraints, if they were disabled..enable them.

SQL> select constraint_name, constraint_type, search_condition,
  2          status from dba_constraints where table_name = 'DEPT';

CONSTRAINT_NAME                C SEARCH_CONDITION     STATUS
------------------------------ - -------------------- --------
SYS_C001489                    C DEPTNO <  22         ENABLED
SYS_C001490                    P                      ENABLED

7. delete the BAD data.
SQL> ED
Wrote file afiedt.buf

  1* DELETE FROM DEPT WHERE ROWID IN  (select row_id from exception_table where table_name='DEPT')
SQL> /
2 rows deleted.

[Updated on: Tue, 31 January 2006 04:09]

Report message to a moderator

Re: SQL*Loader BAD FILE [message #70691 is a reply to message #70629] Mon, 15 July 2002 06:19 Go to previous message
meena
Messages: 36
Registered: December 2000
Member
Thank you so much. This worked for me.

Meena
Previous Topic: Re: FREE OCP PAPERS
Next Topic: Re: calling sqlldr from a stored procedure
Goto Forum:
  


Current Time: Mon Dec 23 06:37:44 CST 2024