SQL Loader reformat non-numeric data to zeroes [message #23461] |
Wed, 11 December 2002 06:27 |
Sam Dougall
Messages: 1 Registered: December 2002
|
Junior Member |
|
|
Can SQL Loader, using a Control file, reformat a field to zeroes if it is not set to numerics. I have a date field, in a delimitered flat bcp file, that is sometimes corrupt. Its destination field, unfortunatebly if defined as Numeric, not VarChar. When the field is corrupt I want to zeroize it. I have looked at DEFAULIF but really what to perform an IsNumeric operation. Please help.
|
|
|
|
Re: SQL Loader reformat non-numeric data to zeroes [message #23518 is a reply to message #23461] |
Sat, 14 December 2002 04:55 |
|
Barbara Boehmer
Messages: 9094 Registered: November 2002 Location: California, USA
|
Senior Member |
|
|
You can create a function that accepts a string and returns the number if it is numeric, or zero if it is not numeric, then use the function in your SQL*Loader control file. Example:
-- function:
CREATE OR REPLACE FUNCTION number_or_zero
(p_string IN VARCHAR2)
RETURN NUMBER
AS
BEGIN
RETURN TO_NUMBER (p_string);
EXCEPTION
WHEN VALUE_ERROR THEN
RETURN 0;
END number_or_zero;
/
-- partial example control file:
LOAD DATA
INFILE delimited_flat.bcp
REPLACE INTO TABLE destination_table
FIELDS TERMINATED BY ','
TRAILING NULLCOLS
(numeric_field ("number_or_zero (:numeric_field)"))
|
|
|