Home » SQL & PL/SQL » SQL & PL/SQL » SQL Loader reformat non-numeric data to zeroes
SQL Loader reformat non-numeric data to zeroes [message #23461] Wed, 11 December 2002 06:27 Go to next message
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 #23463 is a reply to message #23461] Wed, 11 December 2002 07:22 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
Just use the function Is_numeric( which is not a builtit, U you have write your own).
u can use any functions in sqlloader.
our other posting gives, one such function
http://www.orafaq.net/msgboard/plsql/messages/8858.htm
Re: SQL Loader reformat non-numeric data to zeroes [message #23518 is a reply to message #23461] Sat, 14 December 2002 04:55 Go to previous message
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)"))
Previous Topic: pl/sql
Next Topic: PRocedure/Function
Goto Forum:
  


Current Time: Thu May 16 02:43:07 CDT 2024