Home » RDBMS Server » Server Utilities » Want to reject rows with NULL values in particular column
icon14.gif  Want to reject rows with NULL values in particular column [message #167994] Tue, 18 April 2006 05:47 Go to next message
pawansinghal
Messages: 3
Registered: February 2006
Junior Member
Hi,

I am using external tables to read CSV files and an Merge statement to insert/update data into the destination table. One of the column in the destination table is set to NOT NULL. Sometimes, there are NULL values presented in the CSV files for that column. And those rows are not being rejected by External tables. And the MERGE statement fails saying cannot insert null into that column.

How can I make external table to reject rows with NULL values for that particular column and report them in the bad file.

-Thanks
Pawan

[Updated on: Tue, 18 April 2006 05:49]

Report message to a moderator

Re: Want to reject rows with NULL values in particular column [message #168089 is a reply to message #167994] Tue, 18 April 2006 14:12 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9101
Registered: November 2002
Location: California, USA
Senior Member
You can use "LOAD WHEN (not_null_column != BLANKS)" and the rows with null values will go into your discard file (not your bad file) as demonstrated below.

-- test.dat:
1,2,3,
4,,6,
7,8,9,


scott@ORA92> CREATE OR REPLACE DIRECTORY my_dir AS 'c:\oracle'
  2  /

Directory created.

scott@ORA92> CREATE TABLE test
  2    (col1		 NUMBER,
  3  	not_null_column  NUMBER,
  4  	col3		 NUMBER)
  5  ORGANIZATION external
  6    (TYPE ORACLE_LOADER
  7  	DEFAULT DIRECTORY my_dir
  8  	ACCESS PARAMETERS
  9  	  (RECORDS DELIMITED BY NEWLINE
 10  	   LOAD WHEN (not_null_column  != BLANKS)
 11  	   DISCARDFILE 'MY_DIR':'test.dsc'
 12  	   BADFILE     'MY_DIR':'test.bad'
 13  	   LOGFILE     'MY_DIR':'test.log'
 14  	   FIELDS TERMINATED BY ","
 15  	     (col1,
 16  	      not_null_column,
 17  	      col3))
 18    LOCATION ('test.dat'))
 19  /

Table created.

scott@ORA92> SELECT * FROM TEST
  2  /

      COL1 NOT_NULL_COLUMN       COL3
---------- --------------- ----------
         1               2          3
         7               8          9

scott@ORA92>  


-- test.dsc:
4,,6,

icon14.gif  Re: Want to reject rows with NULL values in particular column [message #169278 is a reply to message #167994] Wed, 26 April 2006 01:08 Go to previous message
pawansinghal
Messages: 3
Registered: February 2006
Junior Member
Thanks a lot,

I worked very well.

- Pawan
Previous Topic: Default file location in SQL* Loader
Next Topic: load columns with spaces
Goto Forum:
  


Current Time: Thu Dec 26 08:49:40 CST 2024