Addign a computed column of the record count in table external

Hello

I have a csv file that is loaded using the external table. My need is to give a number to each record in the file and save it in one of the extra column in the table, can anyone suggest how it is possible?

The structure of the file is:
$cat emp.txt
7369,SMITH,CLERK,7902,12/17/1980,800,,20
7499,ALLEN,SALESMAN,7698,2/20/1981,1600,300,30
7521,WARD,SALESMAN,7698,2/22/1981,1250,500,30
7566,JONES,MANAGER,7839,4/2/1981,2975,,20
7654,MARTIN,SALESMAN,7698,9/28/1981,1250,1400,30
7698,BLAKE,MANAGER,7839,5/1/1981,2850,,30
7782,CLARK,MANAGER,7839,6/9/1981,2450,,10
7788,SCOTT,ANALYST,7566,12/9/1982,3000,,20
7839,KING,PRESIDENT,,11/17/1981,5000,,10
7844,TURNER,SALESMAN,7698,9/8/1981,1500,0,30
7876,ADAMS,CLERK,7788,1/12/1983,1100,,20
7900,JAMES,CLERK,7698,12/3/1981,950,,30
7902,FORD,ANALYST,7566,12/3/1981,3000,,20
7934,MILLER,CLERK,7782,1/23/1982,1300,,10

--and the table structure is:

    CREATE TABLE TMP_emp_ext
    (
    EMPNO                                      NUMBER(4),
    ENAME                                              VARCHAR2(10),
    JOB                                                VARCHAR2(9),
    MGR                                                NUMBER(4),
    HIREDATE                                           DATE,
    SAL                                                NUMBER(7,2),
    COMM                                               NUMBER(7,2),
    DEPTNO                                             NUMBER(2)
    )
    ORGANIZATION EXTERNAL
      (  TYPE ORACLE_LOADER
         DEFAULT DIRECTORY DIR_N1
         ACCESS PARAMETERS
           ( records delimited  by newline
        fields  terminated by ','
        missing field values are null
       )
         LOCATION (DIR_N1:'emp.txt')
      )
    REJECT LIMIT UNLIMITED
    NOPARALLEL
    NOMONITORING
 /
Now, my need is to give a number to each record... like the record from 7369, SMITH should be granted record n ° 1, 7499, ALLEN should be record No. 2 etc... can anyone suggest how it is possible?

Thank you
orausern

T. Kyte write RECNUM should work in http://asktom.oracle.com/pls/apex/f?p=100:11:0:P11_QUESTION_ID:52733181746448 #52977916329285 because it is SQL * Loader syntax. However I've wasn't able to make it work with Oracle 10.2.0.4. But in case of errors of loading, you should find in _XXXXX.log the number of rejected records line (in my example it's the meaning of the 'line 2' "line 2"):

erreur lors du traitement de la colonne EMPNO, la ligne 2, pour le fichier de données /tmp/emp.txt
ORA-01722: invalid number

Tags: Database

Similar Questions

  • Search multiple criteria information in the column on the left of a table.

    How to search several criteria information in the column on the left of a table. I am familiar with /match index search values of the left columnn in a table for a "single" column, but not for more than one column?

    Hello

    It seems that you are using Microsoft Office Excel. If yes then it would be better suited in the community of Microsoft Office Excel. I would recommend posting your query in the community of Microsoft Office Excel.

    Microsoft Office Excel community

    http://answers.Microsoft.com/en-us/Office/Forum/Excel

     

    Hope this information helps.

  • delete all the records in a table, the speed of insertion is not change.

    I have an empty table, and I insert a record need 100ms.
    During this table a 40,0000 trace, I insert a record need 1 s, it's ok, because I need to make a comparison according to an index before inserting a record need, so more record, more time.
    The problem is when I delete all the record in this table, the insertion time is always 1s, not reduce to 100ms. Why?

    Hello

    Read this part of the oracle documentation

    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14220/logical.htm#CNCPT004

    The reason is always 1s, because when you inserted 400ko record as HWM (high tide is the border between old and new space in a segment.) moved to the top. And when you remove all records of your HWM still in the same coordinate system and that you have not reset to 0. So when you insert 1 it save free space and after finding faces (usually a regular insertions got 6 steps it inserts data). If you truncate your table you and try it again it will be faster that your HWM is reset to 0.

    Concerning

  • by comparing the records with another table

    Hello
    I have the following 2 tables (test_prs & test_dep) and registers
    My goal is to compare test_prs with test_dep records and return the records that are not in test_dep

    Here is the table scripts
    create table test_prs (id ,p_id ,r_id)
    as
    select 1,200566,200566 from dual
     union all
    select 2,200567,200567
    from dual
    
    create table test_dep (id,de_typ,de_id,de_u_typ,de_u_id)
    as
    select 10,'AS',200566,'PG',200566
    FROM DUAL
    UNION ALL
    select 11,'AS',200567,'PG',200567
    FROM DUAL
    
    
    insert into test_dep 
    select 12,'AS',400189,'PG',400273 FROM dual union all
    select 13,'AS',400273,'PG',400250 FROM dual union all
    select 14,'AS',400273,'PG',400192 FROM dual union all
    select 15,'AS',400273,'PG',400191 FROM dual
    
    insert into test_prs
    select 3,400273,400273 from dual
    I tried the following query to meet my criteria. My output should be null, but all records
    select * from 
    test_prs  prs
    where  exists (select 1 from test_dep de where de.de_id !=prs.p_id and de.de_u_id !=prs.p_id )
    Could you please help me the same

    Published by: smile on 7 March 2012 15:00

    Smile says:
    Thanks for the request

    The query does not work with the following documents

    insert into test_dep
    select 16,'AS',750664,'PG',750758 FROM dual 
    
    insert into test_prs
    select 4,750758,750668 from dual
    

    the r_id should not be put in correspondence with the columns in the test_dep table. P_id must only be put in correspondence

    OK, you want to match against the de_id and the de_u_id p_id? Or a line where either p_id concordances r_id de_u_id or de_id must not be returned?

    To match p_id against de_id and de_u_id, you can write the query like this:

    select id, p_id, r_id from test_prs where
    p_id in
    (select p_id from test_prs
    minus
    select de_id from test_dep
    minus
    select de_u_id from test_dep);
    

    Brgds
    Johan

  • How to read/select only the records from a table with non-English characters

    Hello
    I need to find all records in a table with non-English (mainly Chinese) characters in at least one of the varchar2 columns. Let me kow if someone knows a way by which it can be done using SQL/PLSQL.

    Best regards
    Imran
    select * from your table
    where your_column != convert(your_column, 'UTF8', 'US7ASCII)
    

    Replace UTF8 with your database character set

    Published by: thtsang on October 15, 2009 03:53 - unequal sign change of! =

  • Unable to display the records in a table

    I am a user of a database DB1 U1. The Table T1 is available in a schema/user U2 in the same database DB1. Records are also available in T1.

    The U1 user has select privileges on the table T1. But the select query returns no records in the table T1 for the U1 user. It returns "0 rows. But it has more than 1000 available records in this table, but unable to see those documents. But the U2 user can see these documents and select query retrieves records as usual. How to check what is stopping to select records. How to check what is the method of security set in place which prevents the U1 user to see the records in the table T1.

    Help, please. . I'm naïve...

    Thank you

    You seem to have a virtual private database and/or use of fine-grained access control.

    The two concepts are explained in books online for the version of the database that you didn't disclose it.

    The rules are generally stored in the dictionary DBA_FGA views *.

    --------

    Sybrand Bakker

    Senior Oracle DBA

  • Insert the record of one table to another with the help of the cursor

    Help, please!

    the tables are - 1. countries (country_id pk, country_name, region_id)
    2A (country_id, country_name, region_id)
    table data are
    1 to 1
    2 b 2
    3 C 3
    NULL d 4
    5 e 5
    6 f 6
    7 g 7
    -----------------------
    Insert the record in the table a country table with the help of the cursor, insert all the non-null records.
    This procedure does not correct result
    -----------------------

    create or replace
    Amit procedure as
    cursor c1 is select * from a;
    RW a % rowtype;
    Start
    Open c1;
    Fetch c1 into rw.
    While (C1% found)
    loop
    insert into countries values (rw.country_id, rw.country_name, rw.region_id);
    commit;
    Fetch c1 into rw.
    If rw.country_id is null then
    Fetch c1 into rw.
    end if;
    end loop;
    Close c1;
    exception
    while others then
    dbms_output.put_line ('exception = name ' |) RW.country_name);
    end;

    You don't need cursor at all;

    create or replace procedure amit as
    
    begin
      insert into countries (Country_ID, Country_Name, Region_ID)
      (select a.Country_ID
             ,a.Country_Name
             ,a.Region_ID
       from a
      );
    
      dbms_output.put_line('Rows inserted : ' || sql%rowcount);
    
      commit;
    
    end;
    /
    
  • help in registration of the records from two tables

    HI: I have two tables joined the first field. The field is the primary key in the first table. Need help listing records from both tables with each a line/record results.
    create table EVENTS (
    event_key varchar2(64) primary key,
    event_description varchar2(64),
    create_time int
    );
    
    
    create table EVENT_UPDATES (
    event_key varchar2(64) NOT NULL ,
    update_description varchar2(64),
    update_time int
    );
    
    
    insert into EVENTS values('Event1', 'This is event1', 1);
    insert into EVENT_UPDATES values('Event1', 'Ticket created', 3);
    insert into EVENT_UPDATES values('Event1', 'Event cleared', 10);
    insert into EVENTS values('Event2', 'This is event2', 4);
    insert into EVENT_UPDATES values('Event2', 'Ticket created', 6);
    insert into EVENT_UPDATES values('Event2', 'Event cleared', 8);
    I want to print each record in the table of EVENTS such as a line and the corresponding records in EVENT_UPDATES as a line like this record
    Event1   1     This is event1
                3     Ticket created
                10   Event cleared
    Event2   4     This is event2
                6     Ticket created
                8     Event cleared
    TIA
    Ravi
    select  case weight
              when 1 then event_key
            end key,
            time_val,
            description
      from  (
              select  event_key,
                      create_time time_val,
                      event_description description,
                      1 weight
                from  events
             union all
              select  event_key,
                      update_time,
                      update_description,
                      2 weight
                from  event_updates
            )
      order by event_key,
               weight
    /
    
    KEY          TIME_VAL DESCRIPTION
    ---------- ---------- -------------------------
    Event1              1 This is event1
                        3 Ticket created
                       10 Event cleared
    Event2              4 This is event2
                        6 Ticket created
                        8 Event cleared
    
    6 rows selected.
    
    SQL> 
    

    SY.

  • Comments of the column when the description (desc), one table

    Hello. Is any way to associate a comment with a table column that appear during the description (Desc), one table? I added a column to a table, and I'm almost certain the wire while it will become clear what this column contains exactly. I hope there is a way to add a comment or a Description of a column in my table.

    Any help would be greatly appreciated.

    You can use the

    comment on [table].[column] is 'some text here';
    

    command.

    However the DESCRIBE of sqlplus command appears not only. You will need to write your own table-description using USER_TABLES and USER_TAB_COLUMNS USER_COL_COMMENTS report query.

  • Transpose the text column of the Oracle using ODI table

    Here's what I'm trying to do:
    Source table that contains the columns:
    Time, Blob, Item-ID

    The expected target has the columns:
    Time, data, Item1, Item2. ItemN

    1. where Item1, Item2 are as shown: say for example the source table has 10 rows of different IDS, there are 10 columns in the table target from Item1 to article 10. (Assuming that no. different IDs are fixed)
    How to do this? I learn ODI for a few weeks now. Understand the basics and terminology, I don't know how to do this.

    2 data (the target table) is a return value from a stored procedure that would transform the Blob (of the Source table)
    The stored procedure is ready, but how do you use the procedure to get the target to the source.

    Any help/direction would be greatly helpful.
    -Vincent

    Published by: user12397263 on December 29, 2009 23:53

    1. a question: How do you who would determine row goes to which column? You can say that the 1st line value becomes item1, but without a rank ORDER 1 will always random. If you have a way to ensure the order of the rows (say, a column that can store the rownum) then what you need is in the interface, you specify for n - th element mapping must be MAX (Case when n = rownum then point else ' ' end). Who should take care of it.

    2. There is a way to do this in ODI. Because you are a beginner, I would recommend that you create a temporary table and you use a PL/SQL block to generate data of BLOB and serve another table of the source that can update the column of data in the temporary table target table.

  • How to map a dynamic/computed column in the annotation of persistence?

    I try to use APP to map the results of a query to a class, but one of the columns returned by the query is the result of a subquery - it has no really a column associated with it.

    Example:

    Select a, b, c,.
    case when it exists (select 1 from some_other_table where...) then 'Y' end ' n else as test_flag
    of une_table
    where the...

    This case statement that performs a subquery to produce a result that is not actually mapped to a physical column so I

    How to mark such a situation, so that roll in hibernation, or anything that fills the a property named testFlag when it loads the results of this query?

    Trant says:
    I try to use APP to map the results of a query to a class, but one of the columns returned by the query is the result of a subquery - it has no really a column associated with it.

    Can you share the code? This seems to be the opposite of what JPA or any ORM package is intended; you would usually the ORM package produce SQL statements based on an object model and a query of high level object, but you try here to feed a sort of a pre-existing query object model. As I said - back. You may want to use executeNativeQuery?

    Whenever I am confronted with a situation where a request starts to do involving the unions, subqueries, etc.. I keep the side JPA as stupid as possible. I create a view on the side of the database and that you simply map my entity to this point of view. With appropriate indexing in place which usually performs very well.

  • Validation form column against the value of another Table

    Hello

    I'm new to this forum, so please bear with me a bit!  I only have a small amount of writing PL/SQL experience, and I've never written Javascript or JQuery before.  I am an Oracle DBA and I coding experience C and PERL, so I have a strong technical background.  But I need some advice on the best way to approach a problem.

    I have an application of data base in Oracle Apex (version 4.2) with a tabular form on a table: Let's say that #1 with the conditions of licence 1 a, 1 b, and1C.  I have to make sure that the value entered in col B is not greater than the value of a column in another table (for example table #2 pass 2 (a).  From a conceptual point of view, the amount of money available is in the #2 table, and my tabular form lines are an act of spending money (such as orders or invoices), so I have to make sure that we spend more that we have.  Who is?

    Does anyone have tips for the best way to do it?  I'm figuring that the biggest problem here is perhaps to account for people who enter multiple lines in the form of tables at the same time, right?  So, if a person is entered 3/invoices, I need a total to ensure that they do not have spend more than we have in the #2 table.

    I really appreciate your help!

    Best regards

    Laurie Baublitz

    Ah, I was not totally with you on this charge then. My validation works overall, but it totals the amount for each line, regardless of the task. Okay - who was not totally my solution but more a demonstration of the technique that you can use to validate your tabular presentation in this way.

    You could solve this issue with a safe collection, or with a table plsql where you add an entry for each task name and keep the amount stored in there.

    Anyway, it would be better for you to spend a little time on playback on the plsql collections or collections apex!

    Remember, this is a sample and you will need to take stock of it. The best solutions are those where you need to experiment with 8)

    DECLARE
      TYPE tt_taskamount IS TABLE OF NUMBER INDEX BY VARCHAR2(20);
      t_taskamount tt_taskamount;
    
      l_task VARCHAR2(20);
      l_amount NUMBER;
      l_max NUMBER;
    BEGIN
      -- F02 is the taskname
      -- F03 is the amount
      -- adapt to your situation!
      FOR i IN 1..apex_application.g_f02.count
      LOOP
        l_task := apex_application.g_f02(i);
        l_amount := apex_application.g_f03(i);
        IF NOT t_taskamount.exists(l_task) THEN
          t_taskamount(l_task) := l_amount;
        ELSE
          t_taskamount(l_task) := t_taskamount(l_task) + l_amount;
        END IF;
    
        -- it's not the best idea to perform a select each time and could be
        -- done better but for the sake of the example it's fine
        -- not too bad either if the rowcount is small.
        SELECT maxamount
          INTO l_max
          FROM table2
         WHERE taskname = l_task;
    
        IF t_taskamount(l_task) > l_max THEN
          -- returning will stop further processing and throw an error message as soon as a budget has been overrun
          -- it might or might not be required behaviour but that's up to you
          RETURN 'The max amount ('||l_max||') for task ' || l_task ||' has been exceeded. Reduce the total amount on associated tasks!';
        END IF;
      END LOOP;
    END;
    
  • need help to correct the records in a table

    Hi all

    I loaded a content file in a single table with a single column, the file is to have the data as below
    Record 1.  ABC|AVC1|1234|
                   xyz|abc
    Record 2.  ABC1|AVC1|12334|
                   xyz
                   |ABC
    Record 3. ABC1|AVC1|12334|xyz|ABC
    I need to correct the data in the table above, the 3 reviews. is the correct format I need record1 and record2 look like.

    Note Record1... 3. the text above, I've added. (it's just a real example table a 5million rec)

    Can any of you help me correct this file using plsql query or sql by creating another table which has corrected data

    Logical I think is

    All records must have 4 delimiter if less then wear the next record in the line to the previous line for example

    Record 1. ABC | AVC1 | 1234 | XYZ | ABC

    Even if there is no delimiter on line then also make the next record in the line to the previous line for example

    Record 2. ABC1. AVC1 | 12334 | XYZ
    | ABC


    Like wise cleaning the table and placing it in a new table, to export.

    Oracle version I have is 10g


    Kind regards
    AAK

    This is because you have not changed the subquery factoring section (aka the WITH clause) properly (I suggest that you are looking for this - it's a very useful piece of syntax to have under your belt). You must change as follows:

    with res as (select rn,
                        txt,
                        ceil(sum(length(txt) - length(replace(txt, '|'))) over (order by rn)/4) grp
                 from   t), -- assuming that your table is called t.
       final as (select replace(sys_connect_by_path(txt, '$'), '$') full_txt,
                        level
                 from   res
                 WHERE CONNECT_BY_ISLEAF = 1
                 connect by grp = prior grp
                 and        rn = prior rn + 1)
    select case when length(full_txt) - length(replace(full_txt, '|')) = 4 then full_txt end full_txt
    from   final
    where  case when length(full_txt) - length(replace(full_txt, '|')) = 4 then full_txt end is not null;
    

    ETA: where 4 appears in my query, you will need to change the number of pipes in your line.
    ETA2: and I suspect that you need to change the 5 in the BluShadow query to 1 + the number of pipes in your line.

    Published by: Boneist on March 23, 2010 17:08

  • Update trigger that inserts the record in another table

    I searched the forum and the web for an example like this and I can not find a:

    A field is updated in the TABLE_A and it triggers a single record TABLE_B insert that has the old and the new value of the field.

    I write a lot of complex data warehouse SQL-based reports, but very rarely do much PL/SQL, any help would be appreciated.
    Thanks in advance.

    Hello

    You can specify that the trigger should fire only when certain columns are referenced, like this:

    create or replace trigger test_fund_trig
    before update OF FUNDING
    on table_a
    ...
    

    If you do this, the trigger will not draw on statements such as:

    UPDATE  table_a
    SET     mod_date = SYSDATE;
    

    You should always use an IF statement, as I mentioned earlier, if you do not want to follow the updates where the value of this column has not really changed.

  • Column of the row on a table (using the SQL query)

    Data in my table looks like this.

    Data in the table

    ===============

    COL_1, COL_2

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

    1 ABCD

    2 ABC

    3 ABCDE

    4             AB

    5 ABCDEFGH

    Now, he must, for the entire line, length COL_2 text exceeds 3, display the text remaining in the new line. For example, the first row (COL_1 = 1), COL_2 length is 4, so in SQL output two lines will be displayed as shown below. Also, the last row (COL_1 = 5), the length is 8, then, in SQL, output 3 lines will be displayed as below. And for the COL_1 = 2 & 4, only 1 rank will be displayed as the text COL_2 length is less than or equal to 3.

    OUTPUT

    ===============

    COL_1, COL_2

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

    1 ABC

    1             D

    2 ABC

    ABC 3

    3             DE

    4             AB

    5 ABC

    5 DEF

    5             GH

    We need to implement using SQL only.

    Hello

    the solution of etbin uses recursive subquery factoring available on Oracle 11 g 2.

    Since you have not mentioned your version I write here 2 alternatives using CONNECT BY and Xquery:

    with mydata as

    (

    Select 1 c1, c2 'ABCD' Union double all the

    Select 2, 'ABC' from dual union all

    Select 3, 'ABCDE' from dual union all

    Select option 4, "AB" dual union all

    Select 5, "ABCDEFGH" of the double

    )

    Select c1, substr (c2, level * 3-2, 3) C2

    of mydata

    connect by substr (c2, level * 3-2, 3) is not null

    and c1 = c1 prior

    and prior dbms_random.random is not null;

    C1 C2

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

    1 ABC

    0%

    2 ABC

    ABC 3

    3

    4 AB

    5 ABC

    5 DEF

    5 GH

    9 selected lines.

    with mydata as

    (

    Select 1 c1, c2 'ABCD' Union double all the

    Select 2, 'ABC' from dual union all

    Select 3, 'ABCDE' from dual union all

    Select option 4, "AB" dual union all

    Select 5, "ABCDEFGH" of the double

    )

    Select a.c1, x.c2

    of mydata one

    , xmltable ("ora: tokenize($c2,",")")

    passing regexp_replace (a.c2, '(.{1, 3}) \1 ',',') as "c2".

    path of columns c2 varchar2 (30) '.'

    ) x

    where x.c2 is not null;

    C1 C2

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

    1 ABC

    0%

    2 ABC

    ABC 3

    3

    4 AB

    5 ABC

    5 DEF

    5 GH

    9 selected lines.

    Edit: corrected the Xquery solution using a simplified regexp_replace.

    Kind regards.

    Alberto

Maybe you are looking for