Count the consecutive numbers in a line

Hi all

I recently discovered that we can use Max (decode () Oracle function to rotate the results in a table. I did this very well. However, rotate a table is only part of the solution that I need. The results of the rotating function to something like this:
01,02,03,05,06,07,08,09,10,11,12,13,14,16,17,20,21,23,25
What I really need, is something like this:
1-17, 20-21,23,25
I really don't know how to begin to solve this but so far I have the following query:
SELECT DISTINCT
     MAX(DECODE(wldw.wafernumber,'01', '01')) 
      || MAX(DECODE(wldw.wafernumber,'02', ',02')) 
      || MAX(DECODE(wldw.wafernumber,'03', ',03')) 
      || MAX(DECODE(wldw.wafernumber,'04', ',04')) 
      || MAX(DECODE(wldw.wafernumber,'05', ',05')) 
      || MAX(DECODE(wldw.wafernumber,'06', ',06')) 
      || MAX(DECODE(wldw.wafernumber,'07', ',07')) 
      || MAX(DECODE(wldw.wafernumber,'08', ',08')) 
      || MAX(DECODE(wldw.wafernumber,'09', ',09')) 
      || MAX(DECODE(wldw.wafernumber,'10', ',10')) 
      || MAX(DECODE(wldw.wafernumber,'11', ',11')) 
      || MAX(DECODE(wldw.wafernumber,'12', ',12')) 
      || MAX(DECODE(wldw.wafernumber,'13', ',13')) 
      || MAX(DECODE(wldw.wafernumber,'14', ',14')) 
      || MAX(DECODE(wldw.wafernumber,'15', ',15')) 
      || MAX(DECODE(wldw.wafernumber,'16', ',16')) 
      || MAX(DECODE(wldw.wafernumber,'17', ',17')) 
      || MAX(DECODE(wldw.wafernumber,'18', ',18')) 
      || MAX(DECODE(wldw.wafernumber,'19', ',19')) 
      || MAX(DECODE(wldw.wafernumber,'20', ',20')) 
      || MAX(DECODE(wldw.wafernumber,'21', ',21')) 
      || MAX(DECODE(wldw.wafernumber,'22', ',22')) 
      || MAX(DECODE(wldw.wafernumber,'23', ',23')) 
      || MAX(DECODE(wldw.wafernumber,'24', ',24')) 
      || MAX(DECODE(wldw.wafernumber,'25', ',25'))  AS WAFERS      
FROM a_wiplothistory wl
JOIN Container C ON (wl.containerid = c.containerid OR wl.containerid= c.splitfromid )
JOIN a_wiplotdetailshistory wld ON wl.wiplothistoryid = wld.wiplothistoryid
JOIN a_wiplotdetailswafershistory wldw ON wld.wiplotdetailshistoryid = wldw.wiplotdetailshistoryid
WHERE c.containername = :lot
Thanks for help guys.

Published by: 1001275 on May 15, 2013 18:28

You can use LISTAGG in your version

SQL> with range_data as
  2  (
  3  select min(wafernumber) mn,min(wafernumber)||nullif('-'||max(wafernumber),'-'||min(wafernumber)) txt
  4  from
  5    (
  6     select wafernumber
  7     from wldw
  8     order by wafernumber
  9    )
 10  group by wafernumber-rownum
 11  )
 12  select listagg(txt,',') within group(order by mn) lst
 13  from range_data;

LST
--------------------------------------------------------------------------------
1-17,20-21,23,25

NB: The sample table of Frank is used...

Tags: Database

Similar Questions

  • Separate the phone numbers on several lines

    Hello

    I have a list of phone numbers in a single column. Some cells have 1 phone number, some have 2, and some have 0. Cells with 2 phone numbers are separated by semicolons.

    I need all the phone numbers in a single column with 1 phone number in each row. The order does not matter, so I'll "Sort Ascending" once completed to get rid of the empty cells with no phone number.

    I need a function that takes the numbers after the comma and puts them on their own line in the same column.

    Note that the numbers are in the format: + 1-xxx-xxx-xxxx so if please be aware formatting as text and not as a mathematical equation.

    Thank you in advance.

    Hi B,

    Easy enough, as long as all entries are accurate according to the format you described. Here are two examples, all tous deux two on the same table. The selected cells are part of the first example and are not used in the second.

    End of flag: The two examples use the flag to end on the A11 to indicate when the formulas have reached the end of the list. As entered flag consists of eight occurrences of the text "end" (including the trailing space), with the final space deleted. This will be assimilated by the formula two phone numbers, provide an indicator of the end of each list.


    Example 1:

    Separates the first phone number in column B using this formula in B2, filled up to the last line containing a phone number in column A (or the line beyond if you want that the flag of the 'end').

    B2: = IF (LEN (A) < 1", LEFT(A,15))

    Len (A) checks no entry in its ranks. If that is found, IF put a string NULL. If there is an entry, LEFT out the first 15 characters.

    The second n phone number each line is copied into column C with this similar formula in C2 and filled up to the last line containing an entry in column A.

    C2: is equal to IF (LEN (A) < 16", RIGHT(A,15))

    If there are two numbers in this line from A cell, the semi colon will be the 16th character.

    After having extracted the numbers in two columns:

    Select all the cells in column B of B2 on the last containing a B10 number in this example). Copy.

    Go menu Edition > paste formula results

    Select all the cells in column C of C2 on the last containing a number C10). Copy.

    Click once on the empty cell in column B, following the list of the "first numbers" (B11 in this example).

    Go to edit > paste the results of the formulas.

    You can now sort the table according to the values (telephone numbers) in column B.

    Example 2:

    Separates the first phone number in column B using this formula in B2, filled up to the last line containing a phone number in column A (or the line beyond if you want that the flag of the 'end').

    B2: = IF (LEN (A) < 1", LEFT(A,15))

    Len (A) checks no entry in its ranks. If that is found, IF put a string NULL. If there is an entry, LEFT out the first 15 characters.

    The second phone number n that each line is copied into column B, starting after the cell containing the flag of the 'end '.

    Enter the following formula in the marketing of cells (B12 in the example) and fill down until the formula produces another flag to end.

    B12: = IF (LEN (A2) < 16", RIGHT(A2,15))

    Note that because this version of the formula is not on the same line as the EMF of the cell that is copied the phone number, it must the line included in the references.

    When the terminator is reached:

    Click on each of the cells that contain the end flags, and then press DELETE to remove the flags from the list.

    Select all THE cells B2 at the end of the list of telephone numbers. Copy.

    Go menu Edition > paste formula results

    With replaced by their latest results calculated formulas, you can now sort the table on column B.

    Kind regards

    Barry

  • The name of the Table may be 2 lines

    Can the name of the Table "numbers be 2 lines?

    I don't seem to be able to make a table name two lines.  You can use a box of text instead, while hiding the name of the table:

    Disable the table name in the Table formatter (lower-right)

    Add a text box

  • How to make SQL * more count the comment and blank line numbers?

    Hello

    Parameter
    Value of the parameter
    Oracle versionEnterprise Edition Release 11.2.0.1.0 - 64 bit
    OPERATING SYSTEMLinux Fedora Core 17 (X86_64)

    I would like to know, is it possible to force SQL * Plus to provide the number of the current in the source file line whenever there is an error? I often put in the first line of my script SQLBLANKLINES the VALUE ON that I may be able to put several consecutive blank lines in my code (I do that sometimes, when I find that it is appropriate to make my code more readable or a sequence of instructions which I believe make their logic more comprehensible for the reader of the Group)

    Now the problem is that SQL * Plus will ignore these empty lines and whenever there is an error, the line number in the error message does not match the actual line number in the source file, but it seems to be the last non-empty line in the file.  Consider the following example:

    SET SQLBLANKLINES ON;

    DECLARE
        var PLS_INTEGER := 10;
    BEGIN


       
        var := 20
    END;
    /

    In the code above on line 9 (also counting blank lines), there is an error (no semicolon at the end of the var: = 20) but when I run the script

    SQL * also, here is the error message I get


    SQL > @myscript.sql;

    END;

    *

    ERROR on line 8:

    ORA-06550: line 8, column 1:

    PLS-00103: encountered the symbol "END" when expected in the following way:

    * & = - + ; <>/ is mod remains not rem

    < an exponent (*) > <>or! = or ~ = > = < = <>and like2 or

    like4 likec between | submultiset of type multiset Member

    The symbol ';' was replaced by 'END' continue.


    SQL >


    As you can see the error message indicates that the error was found on line 8, while in the file, it's really on line 9

    As long as the number of lines in the script is limited, this may not be a problem and we can quickly find the actual line number in the code that causes the error, but for a code, including hundreds (or even thousands) of lines and with many comments and blank lines, find line number given by SQL * error message more becomes complicated.

    So my question: is it possible to make SQ * more properly draw the line numbers, as they appear in the source file?

    Thanks in advance,

    Kind regards

    Dariyoosh

    Hi, Dariyoosh,

    The line numbers in error messages are always from the beginning of the statement, but not the file.  The back-end which checks the errors and generates the error message, has no idea if this statement has appeared in your file, even if the statement was in a file at all, or if it comes from multiple files, each with its own line 1.

    You can divide your scripts into parts, so that the long statements, which may lead to error messages, are each in a separate file, so the statement starts on the line 1 of the file.

    For example, you can call a script called fubar.sql, which looks like this:

    SET SQLBLANKLINES ON;
    
    @@fubar_1
    

    Which calls another script, called fubar_1.sql, located on the same directory as fubar.sql, that looks like this

    DECLARE
        var PLS_INTEGER := 10;
    BEGIN
    
        var := 20
    END;
    /
    

    You never call him directly fubar_1.

  • 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?

  • find the counties of consecutive of 0 and 1

    Hello guys.

    I have a table contains only zeros and ones.

    For example: A = [1,1,0,1,0,0,1,1,1,1,1,1,0,0,0,0,1,1,1,1,0,1,1,1,0,0,0,0,0]

    I created two tables, Azeros and Aones. The Aones table contains number of 1 consecutive number. The Azeros table accumulates the counties of consecutive 0s.

    Given the matrix A = [1,1,0,1,0,0,1,1,1,1,1,1,0,0,0,0,1,1,1,1,0,1,1,1,0,0,0,0,0], then

    Aones = [2,1,6,4,3]

    Azeros = [1,2,4,1,5]

    Thus, Aones and Azeros respectively have counts of each set of consecutive ones and zeros.

    I did an algorithm that uses loops and the structure of the case to find the counties of consecutive sets and store them in Aones. Then run the algorithm again for the zeros and store them in Azeros. I'm working on data sets are huge! So, I'm looking for the best solution (the fastest algorithm) to above case.

    Any help?

    Thank you

    WB


  • How to set the 1st online number = 10 and increment 10 whenever you press the button to add a new line. Also enable users to enter the generic numbers, IE 13 and still increment of 10 23 or whatever.

    How to set the 1st online number = 10 and increment 10 whenever you press the button to add a new line. Also enable users to enter the generic numbers, IE 13 and still increment of 10 23 or whatever.

    I already have my chart updated in place with a button that will add new lines when pressed.

    Now, I want to clarify that the 1st row is 10 and all the other rows after this increase by 10. It will also allow users to enter any number they want, and the next line will increment of 10.

    Help please.

    Try changing the line button Add the following JavaScript code

    newRow var = Table1._Row1.addInstance)

    If (newRow.index > 0)

    {

    newRow.NumericField1.rawValue = newRow.resolveNode ('Row1 [-1].) NumericField1') .rawValue + 10;

    }

    You need to change this code to match your name on the form, but basically the method addInstance() returns the new row, the newRow.resolveNode ("Row1 [-1]... will get the value of the previous row and then add 10.

    Concerning

    Bruce

  • Is it possible to convert the standard numbered list to the list that appears on the same line a right after another? As indicated in 1. Text goes here, 2. Text goes here, 3. Insert text here

    Is it possible to convert the standard numbered list to the list that appears on the same line a right after another?

    Instead

    1. Insert text here
    2. Insert text here
    3. Insert text here

    This

    1 text goes here, 2. Text goes here, 3. The text here.

    This revised list can take multiple lines.

    I use InDesign CC2014 - if that makes a difference.

    the only way is to convert numbered in the text (select numbered list > ctrl (or right click) > bulleted & numbered lists > convert numbered text).

    Then, with search - replace, you can change the paragraph returns in space (or in space by commas as in your example)

  • How to count the number or lines in the file

    Hi Experts,

    I'm file as source and Oracle as target. My folder that contains some data that will load the target.
    My requirement is that I want to count the number of lines that contains my folder. Please help me how to count the total number of lines in the file.


    THX,
    Sara.

    Hi Sahaveda,

    Now, I tried and it works.

    Sorry my mistake again.

    I created HR. ETL_FILE_LOG as below:

    CREATE THE TABLE HR. ETL_FILE_LOG (numero_fichier varchar2 (10))

    Below the code will run without error:

    import java.lang as lang

    import java.sql SQL

    import of java.lang.String

    Import os

    disadvantages is sql. DriverManager.getConnection ("<%=snpRef.getInfo("DEST_JAVA_URL")%>", "<%=snpRef.getInfo("DEST_USER_NAME")%>", "<%=snpRef.getInfo("DEST_PASS")%>")

    dblinks = cons.createStatement)

    File1 = Open ('c:\EMP.txt','r')

    Count = 0

    Line = file1. ReadLine()

    all online! ='' :

    Count += 1

    Line = file1. ReadLine()

    File1. Close()

    sqlQuery = "insert into HR. "The values of ETL_FILE_LOG (numero_fichier) (" + str (count) + ' ") '.

    rqQuery = dblinks.execute (sqlQuery)

    jerks. Close()

    Concerning

  • count the lines in a text/csv file.

    Can you advice me how can I get the total number of lines in a text/CSV file please using java code.

    I will get the contents of the text/csv file in a string variable to no not as a file.

    EX: string var = "123\n234\n123\n3456\nsdfsd\n" this is \n in the new line.

    for that I have to get the total rows 5.

    Please advice.

    Thank you.

    I think I have to try a split of the string and see how big the table is either simply to count the number of newline characters. Since you said you have a huge file and your data are contained in 1 chain, then you should be able to do it more conveniently.

  • count the number of lines without using the count function

    Hello
    How count the number of lines without using the count function?

    Thank you

    Assuming that your statistics table are updated:

    select num_rows
    from   all_tables
    where  table_name = 'YOUR_TABLE_NAME_IN_UPPERCASE';  
    

    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14237/statviews_2105.htm#REFRN20286

  • Find and replace all of the odd numbered lines?

    Is their way to search for and replace or delete really, all the odd numbered lines in code view? I have about 12,000 lines of code but you don't need that things on the even lines.

    Thank you very much for the help!

    The odd lines contain random numbers and letters, that's why I can't just find and replace. If they were embedded in a tag, say a 34341 is the way for me to tell dreamweaver to remove all the interval and ? That would solve the problem.

  • Count the number of lines being written?

    I am writing a file using the procedure UTL_FILE. One of the lines will contain a count of all the lines in the file. What is the best way to get this number?

    Thanks in advance

    so I guess you can do something like

    declare
       cnt pls_integer := 5; -- if you want to count the records outside the loop too
    begin
       write_security_record;
       write_file_header;
       write_company;
       loop
          cnt := cnt + 1;
          write_detail;
       end loop;
       write_control;
       write_file_control (cnt);
    end;
    /
    
  • count the numbers peaks

    Hello, I am new user of labview. I want to count the numebr of spikes which will be detected in the pic detetctor.

    now u can suggest me some realted to counts example that appears in the chart or table

    thanq

    2249kumar wrote:

    If the particle has energy (radon) 5 MeV it takes 1. If it was again 5 MeV it takes 2 altogether, it must be with the total counts.

    I assume you mean if the energy of radon will less than 5 more than 5 (threshold), add - it to the count (+ 1).

    Don't count that peaks after having dropped below 5 and then go back on it 5 (rising edge)? hysteresis?

    Also, I assume that you will work on a simple radon energy reading (or point) at a time. Stamps to collect 100 readings in a waveform and then by peak count after collecting your data.

  • Count the number of lines

    I'm continuing OIC to interact with php where I counts the number of errors of multiple table but it gives me error for example $ress = array ();                      $numrow = oci_fetch_all ($ss, $ress, null, null, OCI_FETCHSTATEMENT_BY_ROW);

    you use he or she pursues? I would be careful in taking legal actions against the SPOUT... Sorry, couldn't resist.

    Regarding your problem: do you have an Oracle error message - and one which?

Maybe you are looking for