Count the number of fields in a record of CSV file

Hello

Here's my problem. I need to open a CSV file on a directory and to count the number of fields in a record. I can easily read the first record using the package UTL_FILE, something like:

UTL_FILE.fopen (s_remote_dir, s_csv_file, 'R', 32767);
UTL_FILE.get_line (input_file, buffer_entree);

then I count the number of commas in the buffer in order to get none. fields:

IF buffer_entree IS NOT NULL THEN
n: = < function that counts the number of commas in a string, buffer_entree >
END IF;

However, this method will not work If a comma is present within a field, that is to say:

127763, account "TRA", 1001, 34, _ "1007 main St., apt. 798 "_"
(last field contains a comma)

Please notify.

Kind regards
M.R.

Here is an example of regexp Etbins solution:

SQL> declare
  2     line     varchar2(1000) := '127763, "TRA account", 1001, 34, "1007 main St., apt. 798", 42, "This, and that, and more"';
  3     fields   number;
  4  begin
  5     fields := regexp_count(regexp_replace(line,'".*?"'),',') + 1;
  6     dbms_output.put_line('Number of fields: '||to_char(fields,'TM9'));
  7  end;
  8  /
Number of fields: 7

Edit:
Added the '+ 1', because the number of commas is a less number of fields ;-)

Published by: Kim Berg Hansen on November 2, 2011 08:53

Tags: Database

Similar Questions

  • count the number of records

    I have a control block View1 with some fields, YEAR, MONTH, STAFF and button SEARCH with the trigger button when pressed with the pl/sql code 'go_block (view2); execute_query; »
    View2 is the block of data showing 10 records on canvas with the fields NAME, STAFF, WAGES...
    in the palette view2, property
    Insert allowed the value or not, update enabled is set to no and in which I put a code of clause.
    After pressing the View1 SEARCH get all the required documents output.
    I want to count the number of records of my outings.
    How do I do that... ???


    thnx. (I use 10g)

    ManiKanchan wrote:
    I have a control block View1 with some fields, YEAR, MONTH, STAFF and button SEARCH with the trigger button when pressed with the pl/sql code 'go_block (view2); execute_query; »
    View2 is the block of data showing 10 records on canvas with the fields NAME, STAFF, WAGES...
    in the palette view2, property
    Insert allowed the value or not, update enabled is set to no and in which I put a code of clause.
    After pressing the View1 SEARCH get all the required documents output.
    I want to count the number of records of my outings.
    How do I do that... ???

    thnx. (I use 10g)

    You can use a column with data type number and not the database.
    Set

    calculation mode :summary
    summary function:count
    summarized block:your_block_name
    summarized item:name_column
    

    Hope this helps...

  • How to count the number of data records?

    Hey guys, how to count the number of records, I had on a data object variable?

    Im having a result of sql query in a variable like this:

    oDB.resolveNode("#command").query.select.value = "SELECT * FROM Customers WHERE CliNombre LIKE ' % ' + input1 +" %' ";

    oDB.open ();

    oDB.first ();

    So I need to count the number of records retrieved by this SQL query at the moment. Help please

    Then move the cursor back to the first record after you have your account.

    There is a keyword count in SQL that will allow you to get the account of your request. You can run that first - get your account, and then run the actual query to get the Recordset. This would require a separate data connection. Some examples of code.

    var xfa.event.newText = inName;
    If (inName == "") {}
    App.Alert ("you must enter a name--try again!")
    }
    var nIndex = 0;
    While (xfa.sourceSet.nodes.item (nIndex) .name! = "DataConnection2")
    {
    nIndex ++;
    }

    oDB = xfa.sourceSet.nodes.item (nIndex) .racing var (1); pertaining to the specified data connection node
    App.Alert (ODB.saveXML ("Pretty"));

    var nIndex = 0;
    While (xfa.sourceSet.nodes.item (nIndex) .name! = "DataConnection3")
    {
    nIndex ++;
    }
    var oDBCount = xfa.sourceSet.nodes.item (nIndex) .racing (1); pertaining to the specified data connection node
    Configure sql call DB to get the number of records that match the criteria

    oDBCount.nodes.item (1).query.setAttribute ("text", "commandType");
    oDBCount.nodes.item (1).query.select.nodes.item (0) .value = "Select count (*) from table1 where AcctNumber = '" + inName + "'";
    oDBCount.open)
    oDBCount.close)

    Configure sql call DB to get the specified employee number

    oDB.nodes.item (1).query.setAttribute ("text", "commandType");
    oDB.nodes.item (1).query.select.nodes.item (0) .value = "Select * from table1 where AcctNumber = '" + inName + "'";
    App.Alert (ODB. Nodes.Item (1) .saveXML ("Pretty"));

    now connect to the DB and get a recording
    oDB.open)
    oDB.close ();

    Note the SQL command use the keyword count (take a look at the oDBCount section). This will return a number of return to the cllaer. When I set up the data connection, a node count (*) that appeared there. I dragged to the form and it has created a field called count that the onus at this node. When the query is executed, the number of resulting records returns to this field. You can have hidden it so that your users can not see it and also to change the binding votes to zero, so it is not included in the data file that is submitted when the form is complete.

    Paul

  • Count the number of records between two values of keys (BTREE)

    How can I count the number of keys between two values?

    I use python driver and BTREE access method.

    = >

    Ideally, what I want is a set of whole time series data (intervals may change) to a given number of points on average. The keys are timestamps and the values are the data that it takes on average. I need to count the number of records between two timestamps so that I can divide this figure by the number of points I need and data on average. What is the best way to do it?  Or should I keep the timestamp constant intervals and use the RECNO access method?

    Thank you
    (first post btw... and why is there not a lot of people at stackoverflow that answering the questions of Berkeley DB?)

    BDB is an integrated db and there no internal counters or statistics you might grap to use for this.    You will have to do it manually.

    You can create a cursor, grap the records you want, whenever you get the next card that you bump a counter.

    If you are using RECNO, you can use a slider to obtain the number of registration (DB_GET_RECNO), and if all that you data is in

    sequentail records with no missing documents, you can find the total number of take the last rec #-original rec # + 1 to get a count.

    If you pass the SQL API, you can issue a SQL query to give you a count.  Select count (*) where...

    As you enter the data anyway, so better perhaps to count records as you go along.

    Thank you

    Mike

  • Try to count the number of records where some columns are met

    Using SQL in Toad against an Oracle table, I'm trying to count the number of records in a table where some columns are filled. For
    example, I need to know the total number of records from a table where

    ln_stop_cd is not null - 65000 records
    ln_process_cd is <>- 25000 0 records
    ln_opt_cd is not null - 7500 records

    and the record_type = "A".

    I know that the total individual records as described above. However, I do not know how
    the SQL to show for record_type = 'A' the total count is 97500 records. Any help would be
    appreciated.

    Hello

    It seems that the problem is that the indictment may overlap; You can count the same rank 0, 1, 2 or 3 times, depending on whether 0, 1, 2 or 3 of these 3 independent conditions are met.

    Try something like this:

    SELECT     COUNT (in_stop_cd)
          + COUNT (CASE WHEN in_process_cd  != 0        THEN 1 END)     -- this site doesn't like the other inequality operator
          + COUNT (in_opt_cd)        AS grand_total
    FROM    table1
    WHERE     dt          >= TO_DATE ('01-JUN-2011', 'DD-MON-YYYY')
    AND     dt          <  TO_DATE ('02-JUN-2011', 'DD-MON-YYYY')
    AND     record_type       = 'A'
    ;
    

    You want to make charges without making 3 assists separated through the table. The problem is the 3 original requests had slightly different WHERE clauses.
    Put these conditions in the WHERE clause and make other conditions apply only to the individual counties, either with a column instead of *, or using a CASE statement that contains the condition that applies only to the column.

    Also, the date is not a column name good. Do not compare the DATEs to strings. If your column is really a DATE and you want to ignore the hours, the minutes and seconds, then the best way is to compare the column with 2 other DATES, as shown above. It's more coding, but it is more efficient and more reliable.

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) and also publish outcomes from these data.
    You don't have to display a large amount of data. You can probably give an excellent example of this problem with only 5 or 10 rows of sample data.
    Explain, using specific examples, how you get these results from these data.
    Always tell what version of Oracle you are using.

    Published by: Frank Kulash, August 4, 2011 11:27

  • Count the number of times that that a field is filled

    Help!

    I am building a form with fields of number 10 named task1, task2, task3, etc.. Different users may or may not use all of these fields. For example, a user can only fill 7 of these fields of number 10, while another user can use only 5. I need the form to count the number of the task fields were filled and put that number into a numeric field named TotalTasks.

    Any help is appreciated!

    Gene-O

    OK, here is a corrected version. The code on each of the fields for tasks thise was

    Whereas there is a subform Page2. I renmaed subform Page2 and which caused problems on a couple of

    fields on page 1. Then I updated the code of responsibility and disciplinary fields as well. Everything seems to b working now.

    Paul

  • Count the number of clips to children?

    I have buttons which create specific videos such as a library object named "Clip_1":

    function b_Add_Clip_1(event:MouseEvent):void
    {
    var b:MovieClip = new Clip_1();
    b.Name = 'Clip_1 ";
    container.addChild (b);
    }

    And so on, I can add much Clip_1, Clip_2 by their corresponding buttons. I can't understand how to count the number of those that exist on the stage, however.

    I would like the number of instances of Clip_1 to display in a text field.

    For example: If there are 20 on the stage, the text field should display 20, if it is deleted, it should display 19.

    I would be grateful for helpful tips, thank you.

    (Root [this_part + "_count"] .text) object = String (v_this_part); generates this error: 1105: target of assignment must be a reference value

    You cannot assign a string to an object.

    Try

    Object (root [this_part + "_count"]). Text = String (v_this_part)

  • count the number of girls

    Hello

    I need to count the number of data child inside the id of the parent.

    For example: -.

    There are files in the following path
    x/y/z/c/p - path id 0
    x/y/z/c/m - path id 1
    x/y/z/a/d - path id 4
    x/y/z/b/o - path id 3

    The files are stored in table 1 with ref to the path id.

    The details of the path is in table 2 (i.e. the path and the path id is mapped in table 2)

    My requirement is: -.

    I have to run a sql that gives me the number of files in each folder and subfolder.

    The expected output is: -.

    path path id number of records
    x, y, z, c 9-15 (this should include the number under the path x/y/z/c/p and x/y/z/c/m)
    x/y/z/a 10 7
    x/y/z/b 15 6


    Any suggestions on the same.


    Thank you
    ABY

    This data on the tables? Or are you referring to actual files on a file system?

    If the latter, then XUTL_FINDFILES Chris Poole may be useful...

    http://www.chrispoole.co.UK/apps/xutlff.htm

    If the former, then you need to give us more details on the data (create a table and insert statements etc) because than your current "expected" seem not to be correlated with the paths of the example you gave.

    {message: id = 9360002}

  • validation working is not to count the non-null fields

    I have six fields on the screen, I want to check that at least 3 of them are filled (3)...
    I created a validation as follows to count the non-null fields... but it's not working...
    Please help solve this problem or recommend a better way to do this...


    declare
    number of question_count;
    Start
    question_count: = 0;
    If: p1_t_question_1 is null then
    null;
    on the other
    question_count: =: question_count + 1;
    end if;
    If: p1_t_question_2 is null then
    null;
    on the other
    question_count: =: question_count + 1;
    end if;
    If: p1_t_question_3 is null then
    null;
    on the other
    question_count: =: question_count + 1;
    end if;
    If: p1_t_question_4 is null then
    null;
    on the other
    question_count: =: question_count + 1;
    end if;
    If: p1_t_question_6 is null then
    null;
    on the other
    question_count: =: question_count + 1;
    end if;
    If: p1_t_question_6 is null then
    null;
    on the other
    question_count: =: question_count + 1;
    end if;

    If: question_count > 2 then return false;
    otherwise returns true;
    end if;
    end;

    I'll take a look a bit.
    In the meantime, check if the code as

    If the trim (both '%' from: p1_question_with_nul') = 'null '.

    help

    Ok. Take a look now. I used the function TRIM as shown above and also changed the comparison for questions 3 text based on ' if: p1_question_with_text is null'

    Seems to work now

    CITY

    Published by: city has 23 October 2009 05:26

  • How to count the number of conditionally highlight cells in a column or row

    I'm working on a table to identify problems with my credit rating. So, I have a column that indicates the due date on the invoice and G that contains the date to which I made the payment.

    I'm trying to follow how many times I'm late with payments. I want to improve.

    So if the G column is later than column D, both with the Date formatting. So, now I've highlighted cells and I want to summarize for the year, how many times I was late payments.

    I thought a column G to count the number of days before or after that back I was with payments. But if the sum, it only gives me no useful information. I guess I could count the number of cells with values less than 0.

    I prefer to be able to put in the summary column for G something that said 0-12 years ago has highlighted cells in the column.

    Thank you

    You can not count based on sharing or formatting.  You can, however, be based on the same conditions.

    There are functions:

    COUNTIF() counties based on a condition is true

    and

    COUNTIFS() based on several conditions being true

    = NB. If

    Here is a way.  IT will take an additional column that calculates the "delay" in the days of a payment

    the first two lines are the lines of header

    H3 = IF (COUNTA (D3, G3) > 1, MAX ((G3−D3) DUR2DAYS, 0), "")

    It's shorthand dethrone select cell H3, and type (or copy and paste it here) the formula:

    = IF (COUNTA (D3, G3) > 1, MAX ((G3−D3) DUR2DAYS, 0), "")

    Now select cell H3, copy

    Select the H3 cells at the end of column H, dough

    H1 = "payments late =" & COUNTIF(H,">0")

  • Count the number of zero terms between non zero terms

    Hello.  I have a table of data of zero and nonzero (example: {1 2 56 2 3 0 0 0 0 0 2 3 5 2 3 5 2 0 0 0 0 32 43}) I need to count the number of zeros of each string of zeros and mark that number against the first zero no term following the string of zeros (NOTE (: string is used here as a description of a series of zeros, not a string variable).  So the plot which coordinates since my example would be (5.2) and (4.32).

    I'm clear on the way to the path, but I am unable to store only each final count of consecutive zeros without having unnecessary data in my plot.

    Thanks in advance to all those who have advice!

    -Mike

    Do something like that?

    EDIT: Minor Correction because of the additional function of decrement.

  • How to count the number of edges using counters SMU-6363

    Hello

    I'm counting the number of edges in a test signal in a duration of 50 Ms I use the SMU-6363 map and connect to the TRC test signals 0 SRC (PFI 8). Is that a correct connection? What else do I need hardware wise be a correct set for this application?

    Thank you

    Jeet

    Hi Jeet,

    This configuration is correct. Hardware wise, that's all you need to do.

    Kind regards

    Jorge Fernandez
    Technical sales engineer
    National Instruments
    ____________________________________________
    Certified LabVIEW Associate Developer (CLAD)

  • SE I can count the number of lines of UN chain?

    Hello that tal me preguntaba if hay alguna funcion that can count the number of lines that has string of United Nations, for example digamos than esto tengo:

    Hola

    Como

    estas

    Ok

    Son 4 lines, pero hay una funcion as arroje ese resultado? o tengo than generarlo? alguna idea?

    Saludos, buen dia.

    How to dice "Rube Goldberg" en Español?

  • Count the number of 1 is present in digital waveforms obtained by converting the pulse signals.

    Hello

    I use Analogtodigital.Vi to convert the pulse of the sequences in digital.signals.I am able to get the representation of digital waveforms of impulses.

    But how to count the number of 1 is present in the converted digital waveform. I want to count the number of 1 is present in the digital waveform converted.

    Thanks in advance.

    Have you tried the block scheme of similar to the Digital.vi of opening?

    It creates an array 2D uncompressed 1 and 0, which is the binary 16 bits A/D conversion of each element in the array Y of the input waveform. You can use the DWDT digital Array.vi Boolean to convert a 2D Boolean table. Then convert Boolean values to 1.0 and summarize the array of integers. The sum must be the number of 1 bits in the digital waveforms.

    Lynn

    Note: The VI attached is saved in version 8.6. When I have it saved for the previous Version a warning was generated about the possible differences in the versions. Let me know if it doesn't work, and you are using which version of LV.

  • count the number of repetitions of items

    I want to count the number of repetitions in column 2, which correspond to each of the categories in column 1 in table. Rehearsals in col 2 should be the same issue, so I would get the representatives by category and item.
    Can someone help me please?
    Thanks in advance.


Maybe you are looking for