Truncate a field before inserting

Suppose I have the following text:

Array: mytable

field: username (VARCHAR2 (35))

field: zip (VARCHAR2 (5))

I am importing data from an excel with columns username and zip file. A couple of the usernames contains more than 35 characters, and some postal codes are in the format xxxx-xxxxx, therefore containing more than 5 characters.

I tried to write an insert before truncating the data until they are inserted. For any user name that is longer than 35 characters in Excel, simply truncate the username to the first of 35 characters. Similarly, for any ZIP code which is above 5 characters, just truncate the zip on the first 5 characters.

The trigger for postal codes:

CREATE OR REPLACE

Trigger_zipc RELAXATION

BEFORE INSERTING

ON mytable

FOR EACH LINE

BEGIN

SELECT substr (: new .zip, 1, 5)

IN: new.zip

Double;

END;

However, I get the error: ORA-12899: value too large for column

I understand that this happens because the value is read before my validation, and because the value is too large, it is not allowed to insert.

I'm not sure where to go from here. Any suggestions?


Is it excel file or a csv file.

I think you can look into creating an external table as well.

Before inserting it just to make a substring.

Something along the lines.

CREATE TABLE ext_data (
 username CHAR(500),
  zip CHAR(500))
  ORGANIZATION EXTERNAL (TYPE ORACLE_LOADER DEFAULT DIRECTORY ext_tab_dir
  ACCESS PARAMETERS (FIELDS TERMINATED BY ',')
  LOCATION ('csv.dat'));

insert into mytable
select substr(username,1,35) , substr(zip,1,5) from ext_data;

I hope this helps.

Alvinder

Tags: Database

Similar Questions

  • How to pre-fill a field before inserting the new record in the same block

    I'm obviously new to the forms and need help! I need to insert new records based on the lodge currently in the same block.

    In the block, I specify a lodge (lodge 0000) and run the query for this particular lodge. I want to insert new records
    for lodge 0000. The number of dressing room must be pre-fill with lodge 0000 and I have to do is enter the others
    provide the information.

    How to make a form to pre-fill the field lodge?

    Instead of global variables, why do you not use "Form settings" which are specific to your form? You can use them in the property 'Initial value' similar to global variables.

  • Confirm delete before inserting then have a unique key.

    Hello

    I have a use case where a database field that is entered by the user must be unique.

    In the database, there is already a record for example 'name1 '.

    The user inserts a new record and puts his name 'name1' as well. Then, for some reason any decides to delete the first existing record and tries to save the new record 'name1 '.

    The previous record validation "Name1" is not yet removed, but the new record with 'name1' seeks to insert.

    Then I get the error message: attribute value 'name1' leads to duplicate keys for this type of entity. oracle.jbo.AttrValException...

    Is it possible to run delete before insertion on commit or another work around?

    JDev Version 11.1.2.3.0

    Concerning

    Here is the link which suites for your usecase

    ADF binary Decompilation: customization of the display order of the changes made to the database

    You need to wtite your own custom of the Transactionfactory class.

    Let us know if it works for you

    Thank you

    KT

  • Validate VMName / Hostname in input field before execution of workflow

    I'm trying to understand if it is possible to validate the input fields before you run a workflow. The scenario I have is commissioning a new virtual machine. The user must enter the VMname both host name before sending the workflow. I have a couple of actions which will check to see if a VMname or host name is already in use. I want to be able to go is to stop the user to submit the workflow for execution, if the name entered already exists. Is it possible that I can do this?

    Thank you

    If the action returns an empty (or null), this is considered a successful validation.

    Any non-empty string is considered to be the validation failed, and the string value is displayed as the error message in the presentation of the Workflow Wizard.

    (If your action return type is not a string but something else, and you do not change, you can build expression OGNL in the property editor for custom validation, which will compare the result of GetAction () .call () with the desired value and return an empty string or string of the error message.)

  • NDP project - Check for a field before the next the workflow status

    Hello

    Is it possible to have a similar feature as the conditions of custody (for GSM, SCRM) in a NDP project?.

    I need to check the value of a field before moving on to the next step. I know that there may be some validations customized when you save the project, but I would like to know if it is possible to check the value of a field before moving to the State / the next step.

    Thanks in advance,

    Fernando

    Hi Fernando,

    We support validation on the events of Workflow in a NDP project. If you have installed the pack of the EP, go to \ReferenceImplementations\Validation\Documentation\Validation Objects.xls, you will see a detailed list of events, type ID and so on.

    I don't know what validation you want to put in place, here, I have an example you can make reference to:

    1, add the following to Config\Extensions\ValidationSettings.xml:

    2, restart the iis services

    3, go to one project NDP, erase the data in field of brands, save the project, no error

    workflow 4, this project, error "property marks is required."

    '

    I hope this helps.

    Thank you

    Jessie

  • TRIGGER BEFORE INSERT OR UPDATE OR DELETE

    I want to create a single trigger before each insert or update or delete, a record gets copied into the AUDIT table. works very well on the insertion and to day but you have problem clear.

    Can you please help me debug this error. The problem of mutation.

    create or replace

    BIU_FS_Test_T RELAXATION

    BEFORE INSERT OR UPDATE OR DELETE

    ON FS_Test

    REFERRING AGAIN AS NINE OLD AND OLD

    FOR EACH LINE

    DECLARE

    number of voffender_history_id;

    Start

    IF the INSERTION

    SELECT FS_Test_history_seq. nextval in the double voffender_history_id;

    INSERT INTO FS_Test_history (OFFENDER_HISTORY_ID,

    OFFENDER_ID, FIRST_NAME, MIDDLE_NAME, LAST_NAME.

    SX, SKIN_TONE, HEIGHT, WEIGHT, RACE, EYE_COLOR,

    HAIR_COLOR, BLOOD_TYPE, VARIOUS, DATE_OF_BIRTH.

    PLACE_OF_BIRTH, TRANSACTION)

    VALUES (voffender_history_id,

    : new. OFFENDER_ID,: new. First name: new. MIDDLE_NAME,: new. LAST_NAME,

    : new. RACE: new. SX,: new. SKIN_TONE,: new. HEIGHT: new. WEIGHT: new. EYE_COLOR,

    : new. HAIR_COLOR,: new. BLOOD_TYPE,: new. VARIOUS: new. DATE_OF_BIRTH,

    :new. PLACE_OF_BIRTH,

    "INSERT");

    ELSIF UPDATE

    et (

    NVL (:OLD. First name, 'x') <> nvl():NEW. First name, 'x') or

    NVL (:OLD. MIDDLE_NAME, 'x') <> nvl():NEW. MIDDLE_NAME, 'x') or

    NVL (:OLD. Last_name, 'x') <> nvl():NEW. Last_name, 'x') or

    NVL (:OLD. RACE 0) <> nvl():NEW. RACE 0) or

    NVL (:OLD. SX 0) nvl(:NEW <>.) SX 0) or

    NVL (:OLD. SKIN_TONE 0) <> nvl():NEW. SKIN_TONE 0) or

    NVL (:OLD. HEIGHT 0) <> nvl():NEW. HEIGHT 0) or

    NVL (:OLD. WEIGHT 0) <> nvl():NEW. WEIGHT 0) or

    NVL (:OLD. EYE_COLOR 0) <> nvl():NEW. EYE_COLOR 0) or

    NVL (:OLD. HAIR_COLOR 0) <> nvl():NEW. HAIR_COLOR 0) or

    NVL (:OLD. BLOOD_TYPE 0) <> nvl():NEW. BLOOD_TYPE 0) or

    NVL (:OLD. VARIOUS, ' x') <> nvl():NEW. VARIOUS, ' x') or

    NVL (:OLD. DATE_OF_BIRTH, January 1, 1900 ") <> nvl():NEW. " DATE_OF_BIRTH, January 1, 1900 ") or"

    NVL (:OLD. PLACE_OF_BIRTH 0) <> nvl():NEW. PLACE_OF_BIRTH 0)

    )

    THEN

    SELECT FS_Test_history_seq. nextval in the double voffender_history_id;

    INSERT INTO FS_Test_history (OFFENDER_HISTORY_ID,

    OFFENDER_ID, FIRST_NAME, MIDDLE_NAME, LAST_NAME.

    SX, SKIN_TONE, HEIGHT, WEIGHT, RACE, EYE_COLOR,

    HAIR_COLOR, BLOOD_TYPE, VARIOUS, DATE_OF_BIRTH.

    PLACE_OF_BIRTH, TRANSACTION)

    VALUES (voffender_history_id,

    : new. OFFENDER_ID,: new. First name: new. MIDDLE_NAME,: new. LAST_NAME,

    : new. RACE: new. SX,: new. SKIN_TONE,: new. HEIGHT: new. WEIGHT: new. EYE_COLOR,

    : new. HAIR_COLOR,: new. BLOOD_TYPE,: new. VARIOUS: new. DATE_OF_BIRTH,

    :new. PLACE_OF_BIRTH, "UPDATE");

    ELSIF DELETION THEN

    SELECT FS_Test_history_seq. nextval in the double voffender_history_id;

    SELECT FS_Test_history_seq. nextval in the double voffender_history_id;

    INSERT INTO FS_Test_history (OFFENDER_HISTORY_ID,

    OFFENDER_ID, FIRST_NAME, MIDDLE_NAME, LAST_NAME.

    SX, SKIN_TONE, HEIGHT, WEIGHT, RACE, EYE_COLOR,

    HAIR_COLOR, BLOOD_TYPE, VARIOUS, DATE_OF_BIRTH.

    PLACE_OF_BIRTH, TRANSACTION)

    VALUES (voffender_history_id,

    : new. OFFENDER_ID,: new. First name: new. MIDDLE_NAME,: new. LAST_NAME,

    : new. RACE: new. SX,: new. SKIN_TONE,: new. HEIGHT: new. WEIGHT: new. EYE_COLOR,

    : new. HAIR_COLOR,: new. BLOOD_TYPE,: new. VARIOUS: new. DATE_OF_BIRTH,

    :new. PLACE_OF_BIRTH, 'CLEAR');

    END IF;

    end;

    Error I get

    Error from the 1 in the command line:

    Remove from the fs_test where PK = 41476

    Error report:

    SQL error: ORA-04091: table get OUT. SOR_O_HISTORY is changing, function of triggering/can not see

    ORA-06512: at «GET. » BIU_FS_TEST_T', line 111

    ORA-04088: error during execution of trigger ' EB. BIU_FS_TEST_T'

    04091 00000 - «table %s. » "%s is changing, function of triggering/can not see.

    * Cause: A trigger (or plsql user-defined function that is referenced in)

    ( this statement) attempted to watch (or modify) a table that has been

    in the middle to be modified by the statement that shot.

    * Action: Rewrite the trigger (or function) so it does not read this table.

    PS 11g r2

    Thank you.

    n_shah18-

    Is there a parent-child relationship between the tables involved in the triggering event? Is there a foreign key used above the child table that references the parent table?

    If you have a parent-child relationship and a trigger on the parent table must be running some DML on the child table, and, if the child table as a foreign key (FK) back to the parent table, any DML on the child table will cause a recursive SQL statement to check the constraint. Indirectly, this will cause an exception table mutation.

    So watch the dependencies on SOR_O_HISTORY / FS_TEST_HISTORY/all other related table. A FOREIGN KEY can make it to mutate (no pun intended).

    Hope this will help you find the root cause.

  • Trigger before insert

    Hi, I need help to create a trigger before the insertion of the STA_STARTDATE column in the employees table
    CREATE OR REPLACE TRIGGER trig_start_date
    BEFORE INSERT OF STAFF FOR EACH ROW
    BEGIN
      IF STA_STARTDATE < '01-JAN-1980'
        THEN
            RAISE_APPLICATION_ERROR(-20900, 'No earlier than 1/1/1980');
      END IF;
    END;
    Note: If the declaration is < 01 - JAN-1980 quotes

    When I run the script, it comes up with this error:

    Error report:
    ORA-04073: invalid column list for this type of trigger
    04073 00000 - "list of invalid columns for this type of trigger.
    * Cause: A list of columns has been specified for a non updated trigger type.
    * Action: Delete the column list.

    * fixed by replacing the OF keyword with, but still have a warning

    Published by: 888948 on October 2, 2011 16:48

    Hello

    to use a column in a trigger, the column must have: new for new values, or: old old values before the name of the column, so your if statement should begin with:

    IF :NEW.STA_STARTDATE 
    

    Herald tiomela
    http://htendam.WordPress.com

  • Helps relaxation that fits into another table before insertion

    I have two tables:

    TABLE A as follows:
    x, y, z
    1, 1, 1
    1, 1, 2
    1, 1, 3

    TABLE B as follows
    c, d, e, f
    1, 1, 1, 8
    1, 1, 1, 2
    1, 1, 1, 6
    1, 1, 2, 5
    1, 1, 2, 10
    1, 1, 2, 3
    1, 1, 3, 12
    1, 1, 3, 11
    1, 1, 3, 15


    I want a trigger, BEFORE insertion in the TABLE B, I want to INSERT into TABLE A as follows:

    c = > x
    d = > y
    e = > z

    ONLY IF a (x, y, z) record does not already exist in the TABLE.

    That is to say. If record (1, 1, 3) already exists in the TABLE, we do not try to put it back when you insert in the TABLE B with values containing (1, 1, 3).

    You will need

    CREATE OR REPLACE trig_on_insert
    BEFORE INSERT ON B
    FOR EACH ROW
    IS
       lv_count    NUMBER := 0;
    BEGIN
       SELECT COUNT(1)
         INTO lv_count
         FROM a
        WHERE x = :new.c
          AND y = :new.d
          AND z = :new.e ;
    
       IF ( lv_count = 0 ) THEN
          INSERT INTO A VALUES(:new.c,:new.d ,:new.e);
       END IF;
    END;
    /
    

    Concerning
    Arun

  • Redirect data to another table using before insert trigger.

    Dear all,
    How can I redirect the data to another table in a before Insert trigger? My database is Oracle10g.
    I have a table EMP (EMP_ID, LAST_NAME, SALARY).
    I have another EMP_COPY table with the same structure. I also have a before Insert trigger on the EMP table.
    Based on a condition that I have to redirect the data in table EMP_COPY. Let's say the condition is EMP_ID = 100.
    I fire an insert on EMP table for example INSERT IN EMP(EMP_ID,LAST_NAME,SALARY) VALUES(100,'Dev',500).
    On the inside of the front Insert trigger on the EMP table, I have the code
    IF EMP_ID = 100 THEN
    INSERT INTO EMP_COPY (EMP_ID, LAST_NAME, SALARY)
    VALUES(:NEW.) EMP_ID,: NEW. LAST_NAME,: NEW. SALARY);
    COMMIT;
    ON THE OTHER
    NULL;
    END IF;
    But the problem here is that data goes to EMP table of origin also although I don't want. He should do an Insert into EMP table only if EMP_ID! = 100.

    One way has been to raise a user-defined exception inside the If statement and not handle it so that the original insert on table EMP fails but INSERT comes in the EMP_COPY table. But in this solution since the inside the trigger unhandled exception, it propagates to the calling environment. And I can't stand outside relaxation as the calling environment is a form of Oracle Apps standard that cannot be customized.

    Any kind of help will be highly appreciated that I am fighting for more than two weeks.

    Thanks in advance
    Dev

    Remove the autonomous transaction pragma... and then try again.

  • How do validation before inserting a line when press a button insert create?

    Hi all;

    I use JDev 11.1.1.2.0

    How do for validation before inserting a line when press on create a button insert into ADF11g?

    < af:commandButton actionListener = "#{bindings." CreateInsert.execute}.
    Text = "CreateInsert."
    Disabled = "#{!}" bindings. CreateInsert.enabled}.
    ID = "cb8" / >

    best regards;

    Hello
    You can do per set actionlister with commit and action with createinsert
    Good luck
    lixinzhu

  • Splitting words before inserting into the new table

    SQL> desc company
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     CO_ID                                     NOT NULL NUMBER(9)
     R_DATE                                             TIMESTAMP(0)
     CONAME                                             VARCHAR2(140)
     ESTYR                                              NUMBER(5)
     COUNTRY                                            VARCHAR2(32)
     PRODUCTS                                           VARCHAR2(3900)
    
    SQL> select unique(products) from company where rownum<6;
    
    PRODUCTS
    --------------------------------------------------------------------------------
    bars,tubes,pre-weld seams,isosceles and un-isosceles angles,special profiles,u-p
    rofiles,plates,t-profiles,flanges,tube fittings,round,hollow bars,double-t-profi
    les (ipe und ipb),pipe clamps,flat,special designs according to drawings for new
     products,profiles for floor covering,hexagon
    
    carbon steel bright bars,tool steel bright bars,alloy steel bright bars,stainles
    s steel bright bars
    
    cold rolled coil,e.g sheet,prepainted sheet,galvalume coil,copper scrap,stainles
    s steel sheet,shredded scrap,hms1 and 2,cobalt ore,rail scrap,hot rolled coil,ga
    lvanized sheet,iron ore
    
    PRODUCTS
    --------------------------------------------------------------------------------
    
    ferro alloy producer
    switch technology,special tubes,rails,steel strip,special steel
    I created another table:
    crate table keywords(
    k_id number(14),
    keywords varchar2(500) unique
    );
    
    create sequence keywords_pk_seq
    start with 3484 increment by 1;
    
    create or replace trigger keywords_pk_trig
    before insert on keywords
    referencing new as new
    for each row
    begin
    select keywords_pk_seq.nextval into :new.k_id
    from dual;
    end;
    /
    I want to:
    one) to split columns of company.products where is comma (,) for example, bars, tubes, pre-soudures, tubes will became 4 different as words:
    bars
    tubes
    welds
    tubes

    (b) then I want to insert these words in the table keywords.keywords with condition separated by ignoring the existing keywords.keywords (e.g. tubes came twice, let's get just a tubes) for example
    k_id keywords
    1 bars
    2 tubes
    3 before welding

    Thank you and best regards

    You can use the merge statement:

    for example

    merge into keywords
    using (
    with t as (select 'pipes,taps,spanner,spade,tubes' as txt from dual)
    -- end of sample data
      select distinct REGEXP_SUBSTR (txt, '[^,]+', 1, level) kw
      from t
      connect by level <= length(regexp_replace(txt,'[^,]*'))+1
      ) x
     on (keywords.keyword = x.kw)
    when not matched then insert (id, keyword) values (key_seq.nextval, x.kw)
    /
    

    But keep in mind that the sequence in this example will be updated for each line independently to know if she gets inserted or not.
    If you set the ID using a sequence triggered when inserting then this will solve this problem.

  • Before Insert TRIGGER to create partitions problem

    Hello

    I m having a problem with the following situation in Oracle 8i:

    I have a table TEST_TABLE, which is divided by the beach with a DATE column. The idea is to have a partition for each month, so the HIGH_VALUE of partitions is always the first day of the month following that represents the partition.

    I created a BEFORE TRIGGER INSERT on the table TEST_TABLE, which tests if the partition for the month of registration which is being inserted exists and, in case it doesn´t, a PROC AUTONOMOUS_TRANSACTION is called to create the TRIGGER.

    Running the code below one can see that even if partitions are created as expected, when you try to insert a record with a date greater than the last partition for the first time, this error is returned:
    ORA-14400: inserted partition key exceeds plu legal partition key.

    Note that if you run the same statement again insert, it s inserted correctly on the partition that was created the first try.

    I´ll appreciate any help on this matter.

    code
    ----------------
    CREATE TABLE TEST_TABLE)
    IDENTIFICATION NUMBER,
    DATE OF THE DT
    )
    TABLESPACE USERS
    PARTITION BY RANGE (DT)
    (
    PART_B42009 PARTITION VALUES LESS THAN (TO_DATE ('2009-01-01 00:00:00 ',' YYYY-MM-DD HH24:MI:SS ',' NLS_CALENDAR = GREGORIAN '))
    LOGGING
    TABLESPACE USERS
    );
    /

    CREATE OR REPLACE PROCEDURE SP_ADD_PARTITION (TEST_TABLE P_DATE. DT % TYPE)
    IS
    PRAGMA AUTONOMOUS_TRANSACTION;
    V_STR VARCHAR2 (500);
    BEGIN

    V_STR: = 'ALTER TABLE TEST_TABLE ADD.
    || 'PARTITION BIRD | TO_CHAR ("P_DATE, ' YYYYMM")
    || ' VALUES LESS (TO_DATE ("')).
    || TO_CHAR (ADD_MONTHS (P_DATE, 1), "YYYY-MM"). '-01 00:00:00 ','
    || ((' SYYYY-MM-DD HH24:MI:SS "," NLS_CALENDAR = GREGORIAN "))';

    EXECUTE IMMEDIATE (V_STR);

    END SP_ADD_PARTITION;
    /

    CREATE OR REPLACE TRIGGER TR_B_I_R_TEST_TABLE
    BEFORE INSERTING
    ON TEST_TABLE FOR EACH LINE
    DECLARE
    NUMBER OF V_PARTITION_EXISTS;
    BEGIN

    IF: NEW. DT > = TO_DATE ('2009-01-01 00:00:00 ',' ' YYYY-MM-DD HH24:MI:SS) THEN

    IMMEDIATELY EXECUTE (' SELECT COUNT (1) ")
    || "Of all_tab_partitions atp'."
    || "WHERE atp.table_name ="table_test"'.
    || "AND the atp. Nom_partition =: v1 ')
    IN V_PARTITION_EXISTS
    WITH THE HELP OF "BIRD" | TO_CHAR(:NEW.) "DT,"YYYYMM";)

    IF V_PARTITION_EXISTS = 0 THEN

    DBMS_OUTPUT. Put_line ('Partition [' |]) 'BIRD ' | TO_CHAR(:NEW.) "DT,"YYYYMM"). does not exist!') ;
    DBMS_OUTPUT. Put_line ('creation..');
    SP_ADD_PARTITION (: NEW.) DT);
    DBMS_OUTPUT. Put_line ('success.');

    IMMEDIATELY EXECUTE (' SELECT COUNT (1) ")
    || "Of all_tab_partitions atp'."
    || "WHERE atp.table_name ="table_test"'.
    || "AND the atp. Nom_partition =: v1 ')
    IN V_PARTITION_EXISTS
    WITH THE HELP OF "BIRD" | TO_CHAR(:NEW.) "DT,"YYYYMM";)

    IF V_PARTITION_EXISTS = 1 THEN
    DBMS_OUTPUT. Put_line ("it s visible at this point..");
    ON THE OTHER
    DBMS_OUTPUT. Put_line ("it s not visible at this point..");
    END IF;

    ON THE OTHER

    DBMS_OUTPUT. Put_line ('Partition [' |]) 'BIRD ' | TO_CHAR(:NEW.) DT, "YYYYMM")
    || already exists! ") ;

    END IF;

    END IF;

    DBMS_OUTPUT. Put_line ('continues with insertion...");

    END TR_B_I_R_TEST_TABLE;
    /

    -Go to the low score
    INSERT INTO TABLE_TEST VALUES (1, TO_DATE ('2008-12-31 23:59:59 ',' YYYY-MM-DD HH24:MI:SS'));))

    -Returns the error on the first try
    INSERT INTO TABLE_TEST VALUES (2, TO_DATE ('2009-01-01 00:00:01 ',' YYYY-MM-DD HH24:MI:SS'));))

    ----------------

    It is the use of the pragma AUTONOMOUS TRANSACTION. Your current transaction cannot see the result of this DOF since it occurs outside of the current transaction. The clue is in the name.

    Of course, you cannot run the DDL in a trigger without use of this pragma, so you're pretty much stuck. There is a solution in 11g, but that will not help you. Unfortunately, your only option is to pre-create the partitions required in front of the need. For example, you might have a DBMS JOB to create a partition for the next month, which takes place the last day of each month (or logical date of company).

    Cheers, APC

    blog: http://radiofreetooting.blogspot.com

  • Change the value of a field, based on an another fiekd before inserting...

    I have this situation: I have generate a code (this happens through a database function) when a new record is saved. This code comes from another field of this record (parameter passed to the function). I (have to) use Apex 3, so I can't use the functionality of the Apex 4.

    To be specific: I have a recording of books program. Every book has a unique library code (this isn't the PK). Labrary code is based on the year of publication (e.g. B2010-00035). So after entering a new book, prior to registration, the year of publication (e.g., 2010) is checked, and throug a database function (for example f_get_new_library_code (2010) returns "B2010-00036") library code must be completed.

    How can I do this in the best way, taking into account, I can't use dynamic measurements of Apex 4 (unfortunately).

    Hello

    If you had specified the type of form the response would have been more precisely!

    If it's a form of a row, then you can write a calculation OnSubmit where you call your function.
    If it's a tabular form you will need to write a process OnSubmit after Comp & Val you through the bays of apex_application.g_f and update the necessary tables.

    Kind regards

  • Need to truncate the table before loading new data

    I use sqlldr control file to load a flat file to a table. This file will be provided each month and is a complete replacement file. I need to automate the process to truncate the data already present in the table before loading new records. I can do this in the same ctl file as load or do I need a separate batch file?

    He is the current ctl file:

    DOWNLOAD THE DATA
    INFILE ' D:\DATA\OHNFILES\OHN_PROVIDER_DATA. TXT'
    INSERT
    PRESERVE SPACES
    IN THE WEB OF THE TABLE. OHN_OK_SELECT
    (
    Position of CHKPPO (0001:0003).
    Position of the EFFECTIVEDATE (0004:0011).
    Position of TERMDATE (0012:0019),.
    CRED_ID position (0020:0024).
    LASTNAME position (0025:0099),
    Position of FIRSTNAME (0100:0124),
    Position of MIDDLENAME (0125:0149),
    Position of PROFESSIONALDEGREE (0150:0164),
    Position of PRIMARYSPECIALTYID (0165:0214),
    Position of PRIMARYSUBSPECIALTYID (0215:0264),
    Position of SECONDARYSPECIALTY (0265:0314),
    Position of OKLICENSENO (0315:0329),
    Position of the Nordic Institute of patents (0330:0339),
    Position of TAXIDNO (0340:0348),
    Position of MEDICARENO (0349:0365),
    Position of OFFICEADDRESS (0366:0465),
    Position of BLDGSUITEPO_BOX (0466:0500),
    Position of the CITY (0501:0525),
    Position of the STATE (0526:0527),
    Position of code POSTAL (0528:0537),
    Position of TELEPHONE number (0538:0549),
    Position of FAX number (0550:0561),
    Position of EMAILADDRESS (0562:0611),
    Position of the COUNTY (0612:0631),
    BILLINGADDRESS position (0632:0731),
    BLDGSUITEPO_BOX1 position (0732:0766).
    Ville1 position (0767:0791).
    STATE1 position (0792:0793).
    POSTALCODE1 position (0794:0803).
    Telephone1 position (0804:0815).
    Position of telecopie1 (0816:0827),
    EMAILADDRESS1 position (0828:0877).
    MAILINGADDRESS position (0878:0977),
    BLDGSUITEPO_BOX2 position (0978:1012).
    CITY2 position (1013:1037),
    STATE2 position (1038:1039).
    POSTALCODE2 position (1040:1049).
    Telephone2 position (1050:1061).
    Telecopieur2 position (1062:1073).
    EMAILADDRESS2 position (1074:1123).
    Position of the OST (1124:1163),
    Position of CLINIC_GRPNAME (1164:1263),
    Position of FEESCHEDULEID (1264:1278),
    FILL position (1279:1400)
    )

    customer wrote:
    I use sqlldr control file to load a flat file to a table. This file will be provided each month and is a complete replacement file. I need to automate the process to truncate the data already present in the table before loading new records. I can do this in the same ctl file as load or do I need a separate batch file?

    Same file. Say "TRUNCATE" instead of "INSERT".

    LOAD DATA
    INFILE 'D:\DATA\OHNFILES\OHN_PROVIDER_DATA.TXT'
    TRUNCATE
    PRESERVE BLANKS
    INTO TABLE WEB.OHN_OK_SELECT
    ( ...
    

    Published by: Frank Kulash, on September 3, 2009 15:12

  • Why delete index before insertion?

    Hi all
    I have a table with 5 partitions, I also have 3 indices and 1 local index.
    Before each load, I have to truncate a partition and reload the data in that partition.
    When I tried to insert data into the partition, I got an error called
    ORA-29861: area index is shown LOADING/FAILURE/UNUSABLE
    When I checked my index finger, they were all unusable.
    I don't know if my truncated statement would unusable.
    Once I dropped these unusable indexes, my insert worked.
    Now I guess I have to recreate all the indexes.
    In my view, there is no such thing as enable and disable an Index. It should drop and rebuild them, I guess?

    I have however, the advantage of having a partition is to be able to truncate.
    Kindly let me know if I have to go through this every time I have truncate partition and reload it?
    Kind regards
    AJ

    You shouldn't have to drop and re-create the index.

    Before loading, you should be able to:
    change the index unusable.

    on each index. Then, before loading, do:
    ALTER session set skip_unusable_indexes = true;

    then do the load.

    Finally, do:
    ALTER index rebuilt nologging;

    for each index.

    Hope that helps,

    -Mark

Maybe you are looking for