Spaces value in sql loader

Is there a way to load in spaces using Sql*Loader given that the table it is loading to has a not null column but has a default value. My data file has spaces for a number field instead of zeros. Since my table column is declared as not null, it's failing even if I have a default value of '0' in my column.

You can tackle this in the control file. Here is a snippet from Oracle OnLine books - hopefully this will help out! Cheers.
==========================================
Setting a Column to Null or Zero
If you want all inserted values for a given column to be null, omit the column's specifications entirely. To set a column's values
conditionally to null based on a test of some condition in the logical record, use the NULLIF clause; see NULLIF Keyword. To set a
numeric column to zero instead of NULL, use the DEFAULTIF clause, described next.
DEFAULTIF Clause
Using DEFAULTIF on numeric data sets the column to zero when the specified field condition is true. Using DEFAULTIF on
character (CHAR or DATE) data sets the column to null (compare with Numeric External Datatypes). See also Specifying Field
Conditions for details on the conditional tests.
DEFAULTIF field_condition
A column may have both a NULLIF clause and a DEFAULTIF clause, although this often would be redundant.
Note: The same effects can be achieved with the SQL string and the DECODE function. See Applying SQL Operators to
Fields
NULLIF Keyword
Use the NULLIF keyword after the datatype and optional delimiter specification, followed by a condition. The condition has the same
format as that specified for a WHEN clause. The column's value is set to null if the condition is true. Otherwise, the value remains
unchanged.
NULLIF field_condition
The NULLIF clause may refer to the column that contains it, as in the following example:
COLUMN1 POSITION(11:17) CHAR NULLIF (COLUMN1 = "unknown")
This specification may be useful if you want certain data values to be replaced by nulls. The value for a column is first determined from
the datafile. It is then set to null just before the insert takes place. Case 6: Loading Using the Direct Path Load Method provides
examples of the NULLIF clause.
Note: The same effect can be achieved with the SQL string and the NVL function. See Applying SQL Operators to Fields.
Null Columns at the End of a Record
When the control file specifies more fields for a record than are present in the record, SQL*Loader must determine whether the
remaining (specified) columns should be considered null or whether an error should be generated. The TRAILING NULLCOLS
clause, described in TRAILING NULLCOLS, explains how SQL*Loader proceeds in this case.
==========================================

Similar Messages

  • Filtering column values in sql loader control file

    Hi all,
    i have a file that contains data such as
    111 Test ####### #testme juio# ###
    as you can see, the data is fix length and separate by spaces
    some field will have value such as ### and some column will contain alpha numeric with some # such as juio#
    i am trying to write a ctl file that read the data using position. ex position 1-3 will get 111 and 4-8 for example gets Test and so on.
    what i am trying to do is when a column value contain all # then i want to set to null. if a value contain alpha-numeric and # then load that value
    ex. ####### will translate to null. #testme will be load it as it is since it contain alphanumeric
    can someone help me write a ctl file that read the field by position and apply null to value that contain all #. again, if a field contain # and alphanumeric such as juio#, then that value should be loaded as is. it is only when the value contain all # it should be set to null
    Th

    You do it without it constant
    --sample data file
    1,2,,
    3,4,,
    LOAD DATA
    INFILE 'D:\d.csv'
    INTO TABLE ABC
    FIELDS TERMINATED BY ","
    ( A,
      B,
      C sysdate,
      D "USER"
    )Edited by: J99 on Jul 23, 2009 12:14 PM
    OR use to avoid extra ',' in datafile.
    --sample data file
    1,2
    3,4
    LOAD DATA
    INFILE 'D:\d.csv'
    INTO TABLE ABC
    FIELDS TERMINATED BY "," TRAILING NULLCOLS
    ( A,
      B,
      C sysdate,
      D "USER"
    )

  • Using constant values in SQL Loader control file

    Hi,
    I have a requirement where I need to migrate the data of 6 tables from MS Access into Oracle data base. I have written SQL Loader scripts so that I can create CSV files based on MS Access data and then migrate into Oracle. But in Oracle tables we have 4 common columns like Create_By, Created_Date,Updated_By and Update_Date, and those fields should be taken care by system. So, basically system should update login user ID and sysdate values in respective columns. My question here is, I do not have above mentioned common columns in MS Access tables. So, can I hard code those values in control file by saying
    Created_By CONSTANT user,
    Create_Date CONSTANT TO_CHAR(SYSDATE,'MM/DD/YYYY HH24:MI:SS'),
    Updated_By CONSTANT user,
    Updated_Date CONSTANT TO_CHAR(SYSDATE,'MM/DD/YYYY HH24:MI:SS')
    Please let me know your valuable suggestions.

    You do it without it constant
    --sample data file
    1,2,,
    3,4,,
    LOAD DATA
    INFILE 'D:\d.csv'
    INTO TABLE ABC
    FIELDS TERMINATED BY ","
    ( A,
      B,
      C sysdate,
      D "USER"
    )Edited by: J99 on Jul 23, 2009 12:14 PM
    OR use to avoid extra ',' in datafile.
    --sample data file
    1,2
    3,4
    LOAD DATA
    INFILE 'D:\d.csv'
    INTO TABLE ABC
    FIELDS TERMINATED BY "," TRAILING NULLCOLS
    ( A,
      B,
      C sysdate,
      D "USER"
    )

  • I want to use deafault value in sql loader

    hello to all......
    i want to insert user tty number ,so i can differentiate the data in the
    table...here i am using the deafault key word but it is not work...
    can any one give best way?
    here is my table tmp
    (tmp_field1 CHAR(256),
    TMP_TTYNO CHAR(9));
    here is my coding to insert int he table...
    :global.tmp_ttyno:='1212';
    Text_Io.Put_Line(fctl, 'LOAD DATA');
         Text_Io.Put_Line(fctl, 'INFILE '||:fl_name );
         Text_Io.Put_Line(fctl, 'APPEND INTO TABLE tmp' );
         Text_Io.Put_Line(fctl, 'fields terminated by "|" optionally enclosed by '''||'\\'||''' trailing nullcols' );
         Text_Io.Put_Line(fctl, '(' );
         Text_Io.Put_Line(fctl, 'tmp_field1 CHAR(256)' );
    ----->>>> Text_Io.Put_Line(fctl, 'TMP_TTYNO CHAR(9),DEFAULT='||:global.tty_no );

    You have asked this question in the forum reserved to discuss issues with downloadiung or obtaining Oracle software. I am not quite sure how your question relates to the forum.
    You might want to check the Database - General forum

  • SQL Loader - adding column values

    Hi everybody,
    Is it possible to have a column value in SQL Loader control file that is a function of two other columns. For example I have table of 3 columns c1, c2, c3
    and data file is having c1, c2 and I want to specify c3 as c1+c2 in the control file, so that it's populated in the table while loading data file. I tried this on date column but it gave me error ora-00981.
    Can you tell me exact sysntax if possible.

    LOAD DATA
    INFILE 'C:\SQLLOADER\AREA.TXT'
    APPEND INTO TABLE AREA
    FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
    (c1,
    c2,
    c3 ":c2+:c1"
    kuljeet pal singh

  • Substitution variable in sql load rules file

    Okay gurus,
    I need a little guidance, I have to replace the value of 201020 and 2008 from substitution variables. I have created the variables and set them up globally on the essbase server.
    201020 = FW00
    2008 = FY00
    WHERE ACT.FISCAL_WEEK_ID <= 201020
    AND ACT.FISCAL_YEAR_ID > 2008
    AND RTDIV.DIV IN (1,2,3,4,5,6,7,8,9,99) (This is the query with hard coded values of week and year)
    When i m trying to put sub variables there , its throwing the error. please find below the way i was trying to do it.
    WHERE ACT.FISCAL_WEEK_ID = '&FW00'
    AND ACT.FISCAL_YEAR_ID = '&FY00'
    But unfortunately, its throwing error Error: 1021001 Failed to Establish Connection With SQL Database Server. See log for more information
    I know that this is the generic error because if i put the hard coded value in sql load rules it works fine.
    Is it the right way to out sub var in sql load rules???
    Please advice and thanks in advance.

    Hi Genn,
    I tried to see the app log for sql but i m afraid that there is nothing in there, the only error message which I am getting in app log is this:
    Failed to Establish Connection With SQL Database Server. See log for more information
    Its an ASO cube and initially i was using the variable as FY00 AS "2008" it did not work and than i tried without quotes in variable but is still not working.
    Any idea..thanks in advance.

  • Sql loader loading date

    hi all,
    How is it possible to insert date in table through sql loader.
    Likewise if i have table A
    (Name varchar2(23),Age int,Dateofbirth date)
    when i run sqlloader it through me ORA-01858 Error on dateofbirth
    if i want to insert
    NAME=Neerav,
    AGE=23,
    DATEOFBIRTH=14-08-1985 in table A
    How can we insert date value through SQL LOADER..
    Version:Oracle10g
    Data file FORMAT:TEST.csv
    Thanks in advance,
    Neerav
    Edited by: Neerav999 on Aug 12, 2009 10:31 PM

    Sorry, but I am not your mother & refuse to spoon feed you.
    sqlldr needs to be informed exactly how the STRINGS in the cvs file are formatted to represent DATE.
    Your data does not match the default DATE format.
    The answer can be found if/when you are willing to Read The Fine Manual in URL previously posted.

  • SQL*LOADER Conditional using conventional method

    I need load only the registers that have one determined value,
    using SQL*LOADER with conventional method.
    thanks

    Have you looked at the WHEN clause?
    eg.
    INTO TABLE dept
    WHEN recid = 1
    ( recid ... etc

  • How to load a default value in to a column when using sql loader

    Im trying to load from a flat file using sql loader.
    for 1 column i need to update using a default value
    how to go about this?

    Hi!
    try this code --
    LOAD DATA
       INFILE 'sample.dat'
       REPLACE
       INTO TABLE emp
       empno   POSITION(01:04) INTEGER EXTERNAL NULLIF empno=BLANKS,
       ename   POSITION(06:15)  CHAR,
       job         POSITION(17:25)  CHAR,
       mgr       POSITION(27:30)  INTEGER EXTERNAL NULLIF mgr=BLANKS,
       sal        POSITION(32:39)  DECIMAL EXTERNAL NULLIF sal=BLANKS,
       comm   POSITION(41:48)  DECIMAL EXTERNAL DEFAULTIF comm = 100,
       deptno  POSITION(50:51)  INTEGER EXTERNAL NULLIF deptno=BLANKS,
       hiredate POSITION(52:62) CONSTANT SYSDATE
      )-hope this will solve ur purpose.
    Regards.
    Satyaki De.

  • SQL*Loader and timestamp values

    I'm loading timestamp values (among other data) from a text file into Oracle using SQL*Loader.
    The data I load is formatted like the following:
    2008/11/13 23:55:21.366
    2008/11/13 23:55:22.782
    2008/11/13 23:55:25.879
    Hence my control file look like this:
    TSTAMP TIMESTAMP "YYYY/MM/DD HH24:MI:SS.FF",
    The timestamp data in the input file are in UTC, however I load into a column that is of type "TIMESTAMP(3)", i.e. in server time. This is on purpose. I do not want the data to be in UTC when I look at them.
    Therefore after the load I have to manually do
    UPDATE mytable
    SET tstamp = tstamp + (tstamp - sys_extract_utc(tstamp));
    This update-after-loading actually takes quite some time due to the amount of records. I would like to avoid it and instead do it as part of the load. Is this possible somehow?
    I'm on Oracle 10.2.
    Thanks.

    Hi
    What about setting a special Time Zone in your database?
    You have two options when setting which time zone the database belongs to. You can either qualify it as a displacement from GMT/UTC in the format of 'hh:mm' or you can specify it as a name that has an entry in the V$TIMEZONE table.
    select tzname,tzabbrev from V$TIMEZONE_NAMES;
    select DBTIMEZONE from dual;
    ALTER database SET TIME_ZONE = 'Denmark/Copenhagen';
    select SESSIONTIMEZONE from dual;
    select CURRENT_TIMESTAMP from dual;
    See that link
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14231/create.htm#sthref319
    Edited by: Hub on Dec 7, 2008 3:58 PM

  • SQL Loader-How to insert -ve & date values from flat text file into coloumn

    Question: How to insert -ve & date values from flat text file into coloumns in a table.
    Explanation: In the text file, the negative values are like -10201.30 or 15317.10- and the date values are as DDMMYYYY (like 10052001 for 10th May, 2002).
    How to load such values in columns of database using SQL Loader?
    Please guide.

    Question: How to insert -ve & date values from flat text file into coloumns in a table.
    Explanation: In the text file, the negative values are like -10201.30 or 15317.10- and the date values are as DDMMYYYY (like 10052001 for 10th May, 2002).
    How to load such values in columns of database using SQL Loader?
    Please guide. Try something like
    someDate    DATE 'DDMMYYYY'
    someNumber1      "TO_NUMBER ('s99999999.00')"
    someNumber2      "TO_NUMBER ('99999999.00s')"Good luck,
    Eric Kamradt

  • SQL Loader, nested tables and default values

    Is there a way to specify a default value for a nested table entry when SQL*Loader encounters a 'null' value?
    I want to avoid this:
    Record 5: Rejected - Error on table LEVEL_DESC, column LEVELS.
    NULL nested table element is not allowed

    Use the NULLIF parameter in your control file for the nested table objects.
    e.g
    LOAD DATA
    INFILE 'level_data.dat'
    INTO TABLE LEVEL
    (LEVEL_ID POSITION (01:05) CHAR
    LEVEL_NAME POSITION (07:20)
    LEVEL_DESC COLUMN OBJECT
    (LEVELS POSITION (22:25) CHAR NULLIF LEVEL_DESC.LEVELS=BLNAKS,
    ... ))

  • SQL LOADER. Numeric values loaded as Varchar2 characters

    Dear all,
    please I need your help in this little problem . I am loading using SQL Loader a data file where a field X has a numeric value, and in the Control file it is defined as numeric value as well in the database table but the strange thing is that its values are loaded with the character "E15" at the end of each value.
    The data files are extacted from AS400 , cobol system and loaded using SQL LOADER in he Oracle database 10g.
    What could be the reason?
    I appreciate your help very much , regards

    We can not guess as to what you data looks like nor can we guess as to what your control file indicates.
    Post sufficient information for someone to help you.
    PS: 10g is not a database version ... post the operating system and version information too:
    SELECT * FROM v$version;

  • ORA-01841 Error when value for date col is NULL in .dat (using SQL Loader)

    Hello Gurus,
    I have some data in .dat file which needs to be loaded into oracle table. I am using SQL * Loader to do the job. Although "NULLIF col_name =BLANKS" works for character datatype, but when value for date col is NULL then I get ORA-01841 error. I have to make NULL for all rows withour value for date column
    Early reply will be highly appreciated
    Farooq

    Hi,
    May be this problem is not with the NULLIF. The value for the date column is not in proper date format.
    create table:
    create table kk (empno number, ename varchar2(20), deptno number, hiredate date)
    Control file:
    LOAD DATA
    INFILE 'd:\kk\empdata.dat'
    insert into TABLE kk ( empno position (1:2) integer external,
    ename position(4:5) char NULLIF ename=BLANKS,
    deptno position (7:8) integer external NULLIF deptno=BLANKS,
    hiredate position (10:20) date NULLIF hiredate=BLANKS)
    data file:
    10 KK 01-jan-2005
    20 10
    SELECT * FROM KK;
    EMPNO ENAME DEPTNO HIREDATE
    10 KK 01-JAN-05
    20 10
    Verify the data file.
    Hope it will help

  • Sql Loader INFILE name value in table column Value

    Hi,
    Here is my Sql Loader Script
    LOAD DATA
    infile '%1'
    APPEND INTO TABLE XX_SUPPLIER_UPD
    FIELDS TERMINATED BY ";" OPTIONALLY ENCLOSED BY '"' TRAILING NULLCOLS
    ACTION Char
    ,ADDRESS_TYPE Char
    ,REGION Char "LTRIM(RTRIM(:REGION))"
    ,PO_BOX Char
    ,,WWW_ADDRESS Char
    ,status Char "NVL(:status,'X')"
    ,filename Char "replace(:infile,'\"','')"
    I am getting the infile name as the parameter and i want to insert that parameter value in the column name fillename. Can any one guide me to how to do.
    Cheers!
    Jayaraj.S

    If you were to use external tables instead of SQL*Loader, you can dynamically change the location of the external table (i.e. the filename) using a simple ALTER TABLE statement.
    External tables also mean that all the control is inside the database rather than relying on external utilities and external scripts.
    ;)

Maybe you are looking for