Parse String, split into rows

I have a report who has the following output:
MODEL    PO No   RR No  RR Date,     PartNo           Part Description,              Qty Received   Lot No             DR No.    DR Date     
QB3-DLX  150     100455  3/16/2011   657712S400   ROD HOOD SUPPORT       72                  252-36,253-36 2345       3/15/2011
based on the Lot No column result would be:
MODEL    PO No    RR No    RR Date     PartNo           Part Description              Qty Received    Lot No           DR No.    DR Date     
QB3-DLX  150      100455   3/16/2011  657712S400  ROD HOOD SUPPORT       36                   252-36           2345      3/15/2011
QB3-DLX  150      100455   3/16/2011  657712S400  ROD HOOD SUPPORT       36                   253-36           2345      3/15/2011
How will I parse the Lot No column and have the following result displayed as above?
Thank you in advance.

Hi,
You may do the opposite: i.e. from 2 lines to one. It will be extremely difficult or not possible to meet your above need.
Thanks,
Gordon

Similar Messages

  • Result may contain single string or comma separated need to split into rows

    Hi, All... I've searched through the forums and found plenty on splitting comma separated into rows; though I'm struggling applying it to my situation. I have data that looks like the below where I need to split a value into multiple rows if it should be but the same field in the table may also contain a string that should not be separated (indicated by the "Array" field being 0 or 1)...
    WITH t AS
    (SELECT 1 as array, '"Banana", "Apple", "Pear"' as str FROM dual union all
    SELECT 0, 'Fruit is delicious' FROM dual union all
    SELECT 0, 'So are vegetables' FROM dual union all
    SELECT 1, '"Bean", "Carrot", "Broccoli"' FROM dual union all
    SELECT 1, '"Apple", "Banana"' FROM dual)I've looked through many of the connect_by posts on the forum and I haven't come across one that splits a field if it should be but doesn't if it should not be... may have missed it because there are plenty of these requests on the forum!
    If you're feeling even more ambitious - the ultimate goal is to count the number of times a particular answer appears in an array - so notice the last portion of the data contains "Apple", "Banana"... the result would show:
    RESULT
    Banana             2
    Apple              2
    Pear               1
    Bean               1
    Carrot             1
    Broccoli           1
    Fruit is delicious
    So are vegetablesI can always sort them later based on other fields in the table - but the result above would be my ultimate goal!
    Any help is always appreciated. Thanks! 11g

    Hi,
    The examples you found should work for you. Just use a CASE expression to determine if str needs to be split or not, by looking at array.
    Here's one way:
    WITH     got_part_cnt     AS
         SELECT     array, str
         ,     CASE
                  WHEN  array = 0
                  THEN  1
    --              ELSE  1 + REGEXP_COUNT (str, '", "')     -- See note below
                  ELSE  1 + ( ( LENGTH (str)
                                  - LENGTH (REPLACE (str, '", "'))
                         / 4
              END          AS part_cnt
         FROM    t
    ,     cntr     AS
         SELECT  LEVEL     AS n
         FROM     (
                  SELECT  MAX (part_cnt)     AS max_part_cnt
                  FROM    got_part_cnt
         CONNECT BY     LEVEL     <= max_part_cnt
    ,     got_sub_str          AS
         SELECT     CASE
                  WHEN  p.array = 0
                  THEN  p.str
                  ELSE  REGEXP_SUBSTR ( p.str
                                   , '[^"]+'
                             , 1
                             , (2 * c.n) - 1
              END     AS sub_str
         FROM     got_part_cnt  p
         JOIN     cntr           c  ON  c.n <= p.part_cnt
    SELECT       sub_str
    ,       COUNT (*)     AS cnt
    FROM       got_sub_str
    GROUP BY  sub_str
    ORDER BY  cnt          DESC
    ,            sub_str
    {code}
    The only database at hand right now is Oracle 10.2, which doesn't have REGEXP_COUNT.  I had to use a complicated way of counting how many times '", "' occurs in str in order to test this in Oracle 10.  Since you have Oracle 11, you can un-comment the line that uses REGEXP_COUNT in the first CASE expression, and remove the alternate ELSE clause (that is, the next 5 lines, up to END).
    To make sure that this query is really paying attention to array, I added this row to the sample data:
    {code}
    SELECT 0, '"Bean", "Carrot", "Broccoli"' FROM dual union all
    {code}
    Even though str looks just like a delimited list, array=0 tells the query not to split it, so it produces these results:
    {code}
    SUB_STR                               CNT
    Apple                                   2
    Banana                                  2
    "Bean", "Carrot", "Broccoli"            1
    Bean                                    1
    Broccoli                                1
    Carrot                                  1
    Fruit is delicious                      1
    Pear                                    1
    So are vegetables                       1
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Parsing String Oject into another JFrame page

    Hi,
    Can I know if it is possible to parse a string object into another JFrame page that I had created.
    Say i created a string object called obj, i want to pass the value of the string object "obj" to another JFrame page. How can it be done?
    String obj= new String();
              obj=table.getValueAt(table.getSelectedRow(),table.getSelectedColumn()).toString();Next, can i know how tocheck if a connection exist?
    Like i wann connect to a FTP server and i would like to check in the first place if the connection exist/available.
    appreciate all help.
    thanks.

    Essentially the same problem as solved here: http://forum.java.sun.com/thread.jspa?threadID=698985
    You should keep in mind that there is a difference between static and non-static thingies...
    * what goes into the class and what goes into the objects?
    ...and you should also keep in mind that Java is case sensitive and Java programmers (well, almost everyone) follow the same naming conventions :
    * use Capital letter for classes
    * finals all capital (with undercores denoting words)
    * everything else have lowercase letter
    * capitalize first character whenever "a new word" comes along
    You will keep bashing your head against a wall with minor problems until you figure it out. A "Java naming-ized" version of your (presumed) code might act as some kind of starting point?
    public class Search extends JFrame {
      //instance/object thingies -----------------
      private String aString;            // a instance field (unique for this instance)
      public Search(String anArgument) { // the Search constructor, with an argument
        aString = anArgument;          //do something with the argument ...
      //class thingies -----------------
      public static String str= "Some string";  // a static field (shared by all instances)
      public static void main(String[] args) {  // the main method is static...
        Search frame = new Search(str);      // create the Search object/frame, passing a parameter
        frame.setVisible(true);     
    }

  • Field with comma separated values to be split into Rows using a Query

    Thanks for the Reply.. I also have to Decode each of the spilt values with some text..
    replace(disc_topics,',',chr(10)) A from XYZ
    Disc_topics values are '01,02,03,04,05'
    this has to be done in SQL
    01 Test1
    02 Test2
    03 Test3
    04 Test4

    select replace( replace( replace( replace( '#' || '01,02,03,04,05,10,11', ',', ',#'), '#0','#'),'#','Test'),',',chr(10)) A from XYZ

  • Split Function unable to parse string correctly

    Hi,
    I'm using split function to split string into multiple rows using comma "," as delimiter. In a string I have following values which are not parsed correctly as they have comma inside the values. 
    American Dawn, Inc.
    Battalian USA, Inc.
    Fria USA, Inc.
    Lazer, Inc.
    Mexilink Inc.
    Is there any other approach to fix this issue?
    Here is the split function Im using:
    CREATE Function [dbo].[fnSplit] (
    @List varchar(MAX), 
    @Delimiter char(1)
    Returns @Temp1 Table (
    ItemId int Identity(1, 1) NOT NULL PRIMARY KEY , 
    Item varchar(MAX) NULL 
    As 
    Begin 
    Declare @item varchar(MAX), 
    @iPos int 
    Set @Delimiter = ISNULL(@Delimiter, ';' ) 
    Set @List = RTrim(LTrim(@List)) 
    -- check for final delimiter 
    If Right( @List, 1 ) <> @Delimiter -- append final
    delimiter 
    Select @List = @List + @Delimiter -- get position of
    first element 
    Select @iPos = Charindex( @Delimiter, @List, 1 ) 
    While @iPos > 0 
    Begin 
    -- get item 
    Select @item = LTrim( RTrim( Substring( @List, 1, @iPos
    -1 ) ) ) 
    If @@ERROR <> 0 Break -- remove item form list 
    Select @List = Substring( @List, @iPos + 1, Len(@List)
    - @iPos + 1 ) 
    If @@ERROR <> 0 Break -- insert item 
    Insert @Temp1 Values( @item ) If @@ERROR <> 0 Break 
    -- get position pf next item 
    Select @iPos = Charindex( @Delimiter, @List, 1 ) 
    If @@ERROR <> 0 Break 
    End 
    Return 
    End
    Another user in this forum posted a split function that
    he wrote:
    CREATE FUNCTION dbo.splitter(@string VARCHAR(MAX), @delim CHAR(1))
    RETURNS @result TABLE (id INT IDENTITY, value VARCHAR(MAX))
    AS
    BEGIN
    WHILE CHARINDEX(@delim,@string) > 0
    BEGIN
    INSERT INTO @result (value) VALUES (LEFT(@string,CHARINDEX(@delim,@string)-1))
    SET @string = RIGHT(@string,LEN(@string)-CHARINDEX(@delim,@string))
    END
    INSERT INTO @result (value) VALUES (@string)
    RETURN
    END
    GO
    Both of them are unable to parse above values incorrectly.
    FYI:  String is made of values that are selected
    by user in SSRS report. I think SSRS when combine values , put comma "," between multiple values.
    Any help or guidance would be appreciated.
    ZK

    duplicate of
    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/820ac53c-ce25-4cc7-b828-5875a21d459d/split-function-unable-to-parse-string-correctly-in-ssrs-report?forum=sqlreportingservices
    please dont cross post
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • How to split columns into rows

    Hi All,
    Below is my table structure:=
    SQL> create table split(id number,value varchar2(200));
    Table created.
    SQL> insert into split values(1,'X,Y,Z');
    1 row created.
    SQL> insert into split values(2,'A,B,C');
    1 row created.
    SQL> commit;
    Commit complete.
    Expected Output
    ID Value
    1 X
    1 Y
    1 Z
    2 A
    2 B
    3 C
    I know the feature of converting rows into columns by listagg in Oracle 11g, but is there any feature to convert rows into columns based on a delemiter..."," in my case.
    Please help....
    Thanks
    Arijit

    >
    is there any feature to convert rows into columns based on a delemiter
    >
    Here is one way
    VAR csv VARCHAR2(100)EXEC :csv := 'abc,de,fg,hij,klmn,o,pq,rst,uvw,xyz';
    The query:
    WITH data AS( SELECT SUBSTR(csv, INSTR(csv,',',1,LEVEL)+1,                     INSTR(csv,',',1,LEVEL+1) - INSTR(csv,',',1,LEVEL)-1 ) token    FROM ( SELECT ','||:csv||',' csv FROM SYS.DUAL ) CONNECT BY LEVEL < LENGTH(:csv)-LENGTH(REPLACE(:csv,',',''))+2 )SELECT token  FROM data;See http://projectwownow.blogspot.com/2010/02/oracle-convert-csv-string-into-rows.html

  • Converting comma separated string into rows

    for my procedure  varchar2 is i/p paramter. i will get this i/p from java. this string value is like  'VTP,VR','VM'.
    i want to split taht string into rows  ie o/p will be
    VTR
    VR
    VM.
    how to do this.

    Hi,
    As always, the solution depends on your data, your requirements, and you Oracle version.
    Here's one way:
    -- Simulating Java input with a bind variable:
    VARIABLE  str VARCHAR2 (100)
    EXEC     :str := 'VTP,VR,VM';
    SELECT  LEVEL  AS n
    ,       REGEXP_SUBSTR ( :str
                          , '[^,]+'
                          , 1
                          , LEVEL
                          ) AS str_part
    FROM     dual
    CONNECT BY LEVEL <= 1 + REGEXP_COUNT (:str, ',')
    I'm just guessing that your original string doesn't include single-quotes after VR or before VM.  If it does, you can use TRIM to remove them from the string passed back by REGEXP_SUBSTR.

  • Alv output splitting into two rows when converting into excel sheet.

    Hi frends,
    I have alv report with 60 fields . The report output is coming currently .  But when i am exporting into excel sheet from the option local file--> speadsheet  each row is splitting into two rows including header in excel sheet.
    Please provide your valuable suggestions to avoid this.
    Regards,
    Ramu .
    Edited by: Ramu.K on Sep 8, 2009 5:59 PM

    Hi,
    Please use the grid option and with the Spreadsheet button (CntrShiftF7). Do  "Save as" and save it as excel. It should work.
    Regards,
    Pradyumna

  • Parse string into array for comparison

    Hi All,
    I am trying to parse a string message into an array of numbers so I can check if my event was successful.
    \FF\FE\01\FD\02\00\00\00
    I know I just need to read through and discard the \, but I don't know how to do that in Labview. I just need to check if the 6th byte = 00 or not.
    Thanks! I mostly need help with parsing in labview.

    Assuming this is a plain ASCII string containing the letters 0..F and "\" as delimiter, you can simply used "Spreadsheet string to array" with the following settings:
    Type= 1D U8 array
    format= %x
    delimiter= "\"
    One problem is the extra delimiter at the beginning, so use array subset to skip the first element.
    (EDIT: Ahh, Darin beat me with a similar solution. Mine's a little easier ).
    Message Edited by altenbach on 08-06-2009 04:30 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    StringToArray.png ‏13 KB

  • SQL help, how to split one row into many rows

    Hi,
    I got a question on SQL. One table, structure like this: (2 columns)
    A 123,456,789
    B 012,345
    C 678,901,234
    How to get the final result like below:
    A 123,
    A 456,
    A 789
    B 012,
    B 345,
    C 678,
    C 901,
    C 234
    Do I have to use PL/SQL? Appreciate any thought you have on it!

    i doubt the second column string operation can be acheived within single query to break it into rows.
    but here is the pl/sql to do it.
    SQL> create table test_data(col1 varchar2(5), col2 varchar2(30))
      2  /
    Table created.
    SQL> insert into test_data values('A','123,456,789')
      2  /
    1 row created.
    SQL> insert into test_data values('B','012,345')
      2  /
    1 row created.
    SQL> insert into test_data values('C','678,901,234')
      2  /
    1 row created.
    SQL>
    SQL> set serveroutput on
    SQL>
    SQL> declare
      2    pos   number:=0;
      3    str   test_data.col2%type;
      4  begin
      5    for i in (select col1, col2 from test_data)
      6    loop
      7      str := i.col2||',';
      8      loop
      9        pos := instr(str, ',');
    10        dbms_output.put_line(i.col1||' '||substr(str, 1, pos-1));
    11        str := substr(str, pos+1);
    12        exit when str is null;
    13      end loop;
    14    end loop;
    15  end;
    16  /
    A 123                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
    A 456                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
    A 789                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
    B 012                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
    B 345                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
    C 678                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
    C 901                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
    C 234                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
    PL/SQL procedure successfully completed.

  • Split single row into multiple rows containing time periods

    Hi,
    I have a table with rows like this:
    id, intime, outtime
    1, 2010-01-01 00:10, 2010-01-3 20:00
    I would like to split this row into multiple rows, 1 for each 24hr period in the record.
    i.e. The above should translate into:
    id, starttime, endtime, period
    1, 2010-01-01 00:10, 2010-01-02 00:10, 1
    1, 2010-01-02 00:10, 2010-01-03 00:10, 2
    1, 2010-01-03 00:10, 2010-01-03 20:00, 3
    The first starttime should be the intime and the last endtime should be the outtime.
    Is there a way to do this without hard-coding the 24hr periods?
    Thanks,
    Dan Scott
    http://danieljamesscott.org

    Thanks for all the feedback, Dan.
    It appears that the respective solutions provided will give you: a) different resultsets and b) different performance.
    Regarding your 'truly desired resultset' you haven't answered all questions from my previous post (there are differences in the provided examples), but anyway:
    I found that using CEIL or ROUND makes quite a difference, using my 'simple 3 record testset' (30 records vs. 66 records got initially returned, that's less than half of the original). That's quite a difference. However, I must call it a day (since it's almost midnight) for now, so there's room for more optimizement and I haven't thoroughly tested.
    But this might hopefully make a difference performancewise when compared to my previous 'dreaded example':
    SQL> drop table t;
    Table dropped.
    SQL> create table  t as
      2  select 1 id, to_date('2010-01-01 00:10', 'yyyy-mm-dd hh24:mi') intime, to_date('2010-01-03 20:00', 'yyyy-mm-dd hh24:mi') outtime from dual union all
      3  select 2 id, to_date('2010-02-01 00:10', 'yyyy-mm-dd hh24:mi') intime, to_date('2010-02-05 20:00', 'yyyy-mm-dd hh24:mi') outtime from dual union all
      4  select 3 id, to_date('2010-03-01 00:10', 'yyyy-mm-dd hh24:mi') intime, to_date('2010-03-03 00:10', 'yyyy-mm-dd hh24:mi') outtime from dual;
    Table created.
    SQL> select id
      2  ,      max(intime)+level-1 starttime
      3  ,      case
      4           when level = to_char(max(t.outtime), 'dd')
      5           then max(t.outtime)
      6           else max(t.intime)+level
      7         end outtime
      8  ,      level period      
      9  from   t
    10  connect by level <= round(outtime-intime)
    11  group by id, level
    12  order by 1,2;
            ID STARTTIME           OUTTIME                 PERIOD
             1 01-01-2010 00:10:00 02-01-2010 00:10:00          1
             1 02-01-2010 00:10:00 03-01-2010 00:10:00          2
             1 03-01-2010 00:10:00 03-01-2010 20:00:00          3
             2 01-02-2010 00:10:00 02-02-2010 00:10:00          1
             2 02-02-2010 00:10:00 03-02-2010 00:10:00          2
             2 03-02-2010 00:10:00 04-02-2010 00:10:00          3
             2 04-02-2010 00:10:00 05-02-2010 00:10:00          4
             2 05-02-2010 00:10:00 05-02-2010 20:00:00          5
             3 01-03-2010 00:10:00 02-03-2010 00:10:00          1
             3 02-03-2010 00:10:00 03-03-2010 00:10:00          2
    10 rows selected.
    SQL> By the way: I'm assuming you're on 10g, is that correct?
    Can you give us some information regarding the indexes present on your table?

  • Splitting 1 row into 2 rows

    Hi!
    I need to split this row into 2 rows. The key is the flight_leg_id.
    SELECT * 
    FROM favailability a, favailability b
    WHERE a.from_city  = b.to_city
        AND a.to_city = b.from_city
        AND a.from_city = 'Zurich'
        AND a.service_class = 'Economy'
        AND a.fare_type = 'Economy Flex'
        AND a.flight_date = '01.10.09'
        AND b.from_city = 'London'
        AND b.service_class = 'Economy'
        AND b.fare_type = 'Economy Flex'
        AND b.flight_date = '11.10.09';
    FLIGHT_LEG_ID          CARRIER_CODE FLIGHT_NO              FROM_CITY                                                              ORIGIN DEPT_TIME TO_CITY                                                                DESTINATION ARR_TIME FLIGHT_DATE               AIRCRAFT_TYPE                            BOOKING_CLASS SERVICE_CLASS                  NUM_OF_SEATS           SEATS_OCC              CHECKED_BAG          FARE_BASIS FARE_TYPE                      CURRENCY RT_NET_FARE            OW_FARE                TAX                    SURCHARGES             FARE_TOTAL             FLIGHT_LEG_ID          CARRIER_CODE FLIGHT_NO              FROM_CITY                                                              ORIGIN DEPT_TIME TO_CITY                                                                DESTINATION ARR_TIME FLIGHT_DATE               AIRCRAFT_TYPE                            BOOKING_CLASS SERVICE_CLASS                  NUM_OF_SEATS           SEATS_OCC              CHECKED_BAG          FARE_BASIS FARE_TYPE                      CURRENCY RT_NET_FARE            OW_FARE                TAX                    SURCHARGES             FARE_TOTAL            
    3                      LX           450                    Zurich                                                                 ZRH    07:00     London                                                                 LCY         07:35    01.10.09                  AVRO RJ100                               B             Economy                        57                                            20 kg                LXB        Economy Flex                   EUR      708                                           30,01                  21,24                  759,34                 4                      LX           345                    London                                                                 LHR    06:00     Zurich                                                                 ZRH         08:40    11.10.09                  Airbus A320                              B             Economy                        72                                            20 kg                LXB        Economy Flex                   EUR      707                                           30,01                  35,24                  772,25                
    1 rows selectedHow can I do this?

    BANNER                                                          
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
    PL/SQL Release 10.2.0.1.0 - Production                          
    CORE     10.2.0.1.0     Production                                        
    TNS for 32-bit Windows: Version 10.2.0.1.0 - Production         
    NLSRTL Version 10.2.0.1.0 - Production                          
    5 rows selected
    CREATE TABLE "TEST"."FAVAILABILITY"
       (     "FLIGHT_LEG_ID" NUMBER NOT NULL ENABLE,
         "CARRIER_CODE" VARCHAR2(3 BYTE) NOT NULL ENABLE,
         "FLIGHT_NO" NUMBER(4,0) NOT NULL ENABLE,
         "FROM_CITY" VARCHAR2(70 BYTE) NOT NULL ENABLE,
         "ORIGIN" VARCHAR2(3 BYTE) NOT NULL ENABLE,
         "DEPT_TIME" VARCHAR2(6 BYTE) NOT NULL ENABLE,
         "TO_CITY" VARCHAR2(70 BYTE) NOT NULL ENABLE,
         "DESTINATION" VARCHAR2(6 BYTE) NOT NULL ENABLE,
         "ARR_TIME" VARCHAR2(6 BYTE) NOT NULL ENABLE,
         "FLIGHT_DATE" DATE NOT NULL ENABLE,
         "AIRCRAFT_TYPE" VARCHAR2(40 BYTE) NOT NULL ENABLE,
         "BOOKING_CLASS" CHAR(1 BYTE) NOT NULL ENABLE,
         "SERVICE_CLASS" VARCHAR2(30 BYTE) NOT NULL ENABLE,
         "NUM_OF_SEATS" NUMBER(3,0) NOT NULL ENABLE,
         "SEATS_OCC" NUMBER(3,0),
         "CHECKED_BAG" VARCHAR2(20 BYTE),
         "FARE_BASIS" VARCHAR2(8 BYTE) NOT NULL ENABLE,
         "FARE_TYPE" VARCHAR2(30 BYTE) NOT NULL ENABLE,
         "CURRENCY" VARCHAR2(3 BYTE) NOT NULL ENABLE,
         "RT_NET_FARE" NUMBER(6,2) NOT NULL ENABLE,
         "OW_FARE" NUMBER(5,2),
         "TAX" NUMBER(5,2) NOT NULL ENABLE,
         "SURCHARGES" NUMBER(4,2),
         "FARE_TOTAL" NUMBER(6,2) NOT NULL ENABLE,
          CONSTRAINT "FAVAILABILITY_PK" PRIMARY KEY ("FLIGHT_LEG_ID", "CARRIER_CODE", "FLIGHT_NO", "ORIGIN", "DEPT_TIME", "DESTINATION", "FLIGHT_DATE", "BOOKING_CLASS", "SERVICE_CLASS", "FARE_BASIS", "FARE_TYPE")
      USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "USERS"  ENABLE
       ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "USERS" ;
    Insert into FAVAILABILITY (FLIGHT_LEG_ID,CARRIER_CODE,FLIGHT_NO,FROM_CITY,ORIGIN,DEPT_TIME,TO_CITY,DESTINATION,ARR_TIME,FLIGHT_DATE,AIRCRAFT_TYPE,BOOKING_CLASS,SERVICE_CLASS,NUM_OF_SEATS,SEATS_OCC,CHECKED_BAG,FARE_BASIS,FARE_TYPE,CURRENCY,RT_NET_FARE,OW_FARE,TAX,SURCHARGES,FARE_TOTAL) values (5,'LH',4732,'Frankfurt','FRA','15:15','London','LHR','15:50',to_timestamp('01.10.09','DD.MM.RR HH24:MI:SSXFF'),'Airbus A321-131','P','Economy',190,null,null,'LHP','Economy Basic','EUR',252,null,124.64,15,376.64);
    Insert into FAVAILABILITY (FLIGHT_LEG_ID,CARRIER_CODE,FLIGHT_NO,FROM_CITY,ORIGIN,DEPT_TIME,TO_CITY,DESTINATION,ARR_TIME,FLIGHT_DATE,AIRCRAFT_TYPE,BOOKING_CLASS,SERVICE_CLASS,NUM_OF_SEATS,SEATS_OCC,CHECKED_BAG,FARE_BASIS,FARE_TYPE,CURRENCY,RT_NET_FARE,OW_FARE,TAX,SURCHARGES,FARE_TOTAL) values (5,'LH',4732,'Frankfurt','FRA','15:15','London','LHR','15:50',to_timestamp('03.10.09','DD.MM.RR HH24:MI:SSXFF'),'Airbus A321-131','P','Economy',190,null,null,'LHP','Economy Basic','EUR',252,null,124.64,15,376.64);
    Insert into FAVAILABILITY (FLIGHT_LEG_ID,CARRIER_CODE,FLIGHT_NO,FROM_CITY,ORIGIN,DEPT_TIME,TO_CITY,DESTINATION,ARR_TIME,FLIGHT_DATE,AIRCRAFT_TYPE,BOOKING_CLASS,SERVICE_CLASS,NUM_OF_SEATS,SEATS_OCC,CHECKED_BAG,FARE_BASIS,FARE_TYPE,CURRENCY,RT_NET_FARE,OW_FARE,TAX,SURCHARGES,FARE_TOTAL) values (5,'LH',4732,'Frankfurt','FRA','15:15','London','LHR','15:50',to_timestamp('04.10.09','DD.MM.RR HH24:MI:SSXFF'),'Airbus A321-131','P','Economy',190,null,null,'LHP','Economy Basic','EUR',252,null,124.64,15,376.64);
    Insert into FAVAILABILITY (FLIGHT_LEG_ID,CARRIER_CODE,FLIGHT_NO,FROM_CITY,ORIGIN,DEPT_TIME,TO_CITY,DESTINATION,ARR_TIME,FLIGHT_DATE,AIRCRAFT_TYPE,BOOKING_CLASS,SERVICE_CLASS,NUM_OF_SEATS,SEATS_OCC,CHECKED_BAG,FARE_BASIS,FARE_TYPE,CURRENCY,RT_NET_FARE,OW_FARE,TAX,SURCHARGES,FARE_TOTAL) values (5,'LH',4732,'Frankfurt','FRA','15:15','London','LHR','15:50',to_timestamp('05.10.09','DD.MM.RR HH24:MI:SSXFF'),'Airbus A321-131','P','Economy',190,null,null,'LHP','Economy Basic','EUR',252,null,124.64,15,376.64);
    Insert into FAVAILABILITY (FLIGHT_LEG_ID,CARRIER_CODE,FLIGHT_NO,FROM_CITY,ORIGIN,DEPT_TIME,TO_CITY,DESTINATION,ARR_TIME,FLIGHT_DATE,AIRCRAFT_TYPE,BOOKING_CLASS,SERVICE_CLASS,NUM_OF_SEATS,SEATS_OCC,CHECKED_BAG,FARE_BASIS,FARE_TYPE,CURRENCY,RT_NET_FARE,OW_FARE,TAX,SURCHARGES,FARE_TOTAL) values (5,'LH',4732,'Frankfurt','FRA','15:15','London','LHR','15:50',to_timestamp('06.10.09','DD.MM.RR HH24:MI:SSXFF'),'Airbus A321-131','P','Economy',190,null,null,'LHP','Economy Basic','EUR',252,null,124.64,15,376.64);
    Insert into FAVAILABILITY (FLIGHT_LEG_ID,CARRIER_CODE,FLIGHT_NO,FROM_CITY,ORIGIN,DEPT_TIME,TO_CITY,DESTINATION,ARR_TIME,FLIGHT_DATE,AIRCRAFT_TYPE,BOOKING_CLASS,SERVICE_CLASS,NUM_OF_SEATS,SEATS_OCC,CHECKED_BAG,FARE_BASIS,FARE_TYPE,CURRENCY,RT_NET_FARE,OW_FARE,TAX,SURCHARGES,FARE_TOTAL) values (5,'LH',4732,'Frankfurt','FRA','15:15','London','LHR','15:50',to_timestamp('07.10.09','DD.MM.RR HH24:MI:SSXFF'),'Airbus A321-131','P','Economy',190,null,null,'LHP','Economy Basic','EUR',252,null,124.64,15,376.64);
    Insert into FAVAILABILITY (FLIGHT_LEG_ID,CARRIER_CODE,FLIGHT_NO,FROM_CITY,ORIGIN,DEPT_TIME,TO_CITY,DESTINATION,ARR_TIME,FLIGHT_DATE,AIRCRAFT_TYPE,BOOKING_CLASS,SERVICE_CLASS,NUM_OF_SEATS,SEATS_OCC,CHECKED_BAG,FARE_BASIS,FARE_TYPE,CURRENCY,RT_NET_FARE,OW_FARE,TAX,SURCHARGES,FARE_TOTAL) values (6,'LH',4727,'London','LHR','11:50','Frankfurt','FRA','14:20',to_timestamp('20.10.09','DD.MM.RR HH24:MI:SSXFF'),'Airbus A321-131','G','Economy',190,null,null,'LHG','Economy Basic','EUR',252,null,0,0,252);
    Insert into FAVAILABILITY (FLIGHT_LEG_ID,CARRIER_CODE,FLIGHT_NO,FROM_CITY,ORIGIN,DEPT_TIME,TO_CITY,DESTINATION,ARR_TIME,FLIGHT_DATE,AIRCRAFT_TYPE,BOOKING_CLASS,SERVICE_CLASS,NUM_OF_SEATS,SEATS_OCC,CHECKED_BAG,FARE_BASIS,FARE_TYPE,CURRENCY,RT_NET_FARE,OW_FARE,TAX,SURCHARGES,FARE_TOTAL) values (6,'LH',4727,'London','LHR','11:50','Frankfurt','FRA','14:20',to_timestamp('21.10.09','DD.MM.RR HH24:MI:SSXFF'),'Airbus A321-131','G','Economy',190,null,null,'LHG','Economy Basic','EUR',252,null,0,0,252);
    Insert into FAVAILABILITY (FLIGHT_LEG_ID,CARRIER_CODE,FLIGHT_NO,FROM_CITY,ORIGIN,DEPT_TIME,TO_CITY,DESTINATION,ARR_TIME,FLIGHT_DATE,AIRCRAFT_TYPE,BOOKING_CLASS,SERVICE_CLASS,NUM_OF_SEATS,SEATS_OCC,CHECKED_BAG,FARE_BASIS,FARE_TYPE,CURRENCY,RT_NET_FARE,OW_FARE,TAX,SURCHARGES,FARE_TOTAL) values (6,'LH',4727,'London','LHR','11:50','Frankfurt','FRA','14:20',to_timestamp('22.10.09','DD.MM.RR HH24:MI:SSXFF'),'Airbus A321-131','G','Economy',190,null,null,'LHG','Economy Basic','EUR',252,null,0,0,252);
    Insert into FAVAILABILITY (FLIGHT_LEG_ID,CARRIER_CODE,FLIGHT_NO,FROM_CITY,ORIGIN,DEPT_TIME,TO_CITY,DESTINATION,ARR_TIME,FLIGHT_DATE,AIRCRAFT_TYPE,BOOKING_CLASS,SERVICE_CLASS,NUM_OF_SEATS,SEATS_OCC,CHECKED_BAG,FARE_BASIS,FARE_TYPE,CURRENCY,RT_NET_FARE,OW_FARE,TAX,SURCHARGES,FARE_TOTAL) values (6,'LH',4727,'London','LHR','11:50','Frankfurt','FRA','14:20',to_timestamp('23.10.09','DD.MM.RR HH24:MI:SSXFF'),'Airbus A321-131','G','Economy',190,null,null,'LHG','Economy Basic','EUR',252,null,0,0,252);
    Insert into FAVAILABILITY (FLIGHT_LEG_ID,CARRIER_CODE,FLIGHT_NO,FROM_CITY,ORIGIN,DEPT_TIME,TO_CITY,DESTINATION,ARR_TIME,FLIGHT_DATE,AIRCRAFT_TYPE,BOOKING_CLASS,SERVICE_CLASS,NUM_OF_SEATS,SEATS_OCC,CHECKED_BAG,FARE_BASIS,FARE_TYPE,CURRENCY,RT_NET_FARE,OW_FARE,TAX,SURCHARGES,FARE_TOTAL) values (6,'LH',4727,'London','LHR','11:50','Frankfurt','FRA','14:20',to_timestamp('24.10.09','DD.MM.RR HH24:MI:SSXFF'),'Airbus A321-131','G','Economy',190,null,null,'LHG','Economy Basic','EUR',252,null,0,0,252);
    Insert into FAVAILABILITY (FLIGHT_LEG_ID,CARRIER_CODE,FLIGHT_NO,FROM_CITY,ORIGIN,DEPT_TIME,TO_CITY,DESTINATION,ARR_TIME,FLIGHT_DATE,AIRCRAFT_TYPE,BOOKING_CLASS,SERVICE_CLASS,NUM_OF_SEATS,SEATS_OCC,CHECKED_BAG,FARE_BASIS,FARE_TYPE,CURRENCY,RT_NET_FARE,OW_FARE,TAX,SURCHARGES,FARE_TOTAL) values (6,'LH',4727,'London','LHR','11:50','Frankfurt','FRA','14:20',to_timestamp('25.10.09','DD.MM.RR HH24:MI:SSXFF'),'Airbus A321-131','G','Economy',190,null,null,'LHG','Economy Basic','EUR',252,null,0,0,252);Edited by: user545194 on 30-Sep-2009 06:29

  • Turning parts of a string into rows in another table

    I need to extract unit codes that are stored in a string into rows in a new table as below
    From:
    Set_cd         sequence_number         rule_text
    KP106A         15432         {1234,4567,8910,1567}
    To:
    Set_cd         sequence_number         unit
    KP106A         15432         1234
    KP106A         15432         4567
    KP106A         15432         8910
    KP106A         15432         1567
    The strings will be of varying lengths but the layout will always be the same with the curley brackets and commas.
    Any ideas please?
    Thanx
    Rob.
    Edited by: Rob Mc on Sep 23, 2009 2:38 PM

    Something like this ->
    satyaki>
    satyaki>select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
    PL/SQL Release 10.2.0.1.0 - Production
    CORE    10.2.0.1.0      Production
    TNS for Linux: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    Elapsed: 00:00:00.03
    satyaki>
    satyaki>
    satyaki>with ta_tab
      2  as
      3    (
      4      select 'KP106A' set_cd, 15432 sequence_number, '{1234,4567,8910,1567}' rule_text from dual
      5    )
      6  select set_cd,
      7         sequence_number,
      8         REGEXP_SUBSTR (replace(replace(rule_text,'{',''),'}',''), '[^,]+', 1, level) rule_part
      9  from ta_tab
    10  connect by level <= (
    11                         select length(regexp_replace(replace(replace(rule_text,'{',''),'}',''),'[^,]*'))+1
    12                        from ta_tab
    13                      );
    SET_CD SEQUENCE_NUMBER RULE_PART
    KP106A           15432 1234
    KP106A           15432 4567
    KP106A           15432 8910
    KP106A           15432 1567
    Elapsed: 00:00:01.02
    satyaki>
    satyaki>Regards.
    Satyaki De.

  • Please - immediate help needed parsing csv values into multiple rows

    Hello, we have a very immediate need to be able to parse out a field of comma separated values into individual rows. The following is an example written in SQL Server syntax which does not work in Oracle.
    The tricky part is that each ROUTES can be a different length, and each CSV can have a different number of routes in it.
    Here is an example of the table ("Quotes") of CSV values I want to normalize:
    TPNUMBER ROUTES
    1001 1, 56W, 18
    1002 2, 16, 186, 28
    Here is an example of what I need it to look like:
    TPNUMBER ROUTES
    1001 1
    1001 56W
    1001 18
    1002 2
    1002 16
    1002 186
    1002 28
    Here is the "Tally" table for the query below:
    ID
    1
    2
    3
    4
    5
    6
    7
    And finally, here is the query which parses CSV values into multiple rows but which does not work in Oralce:
    SELECT TPNUMBER,
    NullIf(SubString(',' + ROUTES + ',' , ID , CharIndex(',' , ',' + ROUTES + ',' , ID) - ID) , '') AS ONEROUTE
    FROM Tally, Quotes
    WHERE ID <= Len(',' + ROUTES + ',') AND SubString(',' + Phrase + ',' , ID - 1, 1) = ','
    AND CharIndex(',' , ',' + ROUTES + ',' , ID) - ID > 0
    It may be necessary to use a cursor to loop through the CSV table and process each row (a loop within another loop...) but this is beyond my comprehesion of PL/SQL.
    Many thanks in advance for your advice/help.
    apk

    Not sure what you are trying to do with the last step, but this should work for the first part. I assume you would use sqlldr but I just did inserts instead. You might need more than 5 "routes" in the csv. You could put some reasonable max on that number of columns:
    SQL>create table t_csv
    2 (TPNUMBER varchar2(20),
    3 ROUTE_1 VARCHAR2(5),
    4 ROUTE_2 VARCHAR2(5),
    5 ROUTE_3 VARCHAR2(5),
    6 ROUTE_4 VARCHAR2(5),
    7 ROUTE_5 VARCHAR2(5),
    8 ROUTE_6 VARCHAR2(5) );
    Table created.
    SQL>INSERT INTO t_csv (TPNUMBER,ROUTE_1,ROUTE_2) values( '1001 1', '56W', '18' );
    1 row created.
    SQL>INSERT INTO t_csv (TPNUMBER,ROUTE_1,ROUTE_2,ROUTE_3) values( '1002 2', '16', '186', '28');
    1 row created.
    SQL>create table t_quotes(
    2 tpnumber NUMBER,
    3 routes VARCHAR2(5));
    Table created.
    SQL>DECLARE
    2 L_tpnumber NUMBER;
    3 L_route VARCHAR2(5);
    4 begin
    5 for rec in (select * from t_csv) loop
    6 L_tpnumber := SUBSTR(rec.tpnumber,1,INSTR(rec.tpnumber,' ')-1);
    7 L_route := SUBSTR(rec.tpnumber,INSTR(rec.tpnumber,' ')+1);
    8 insert into t_quotes values( L_tpnumber, l_route );
    9 if rec.route_1 is not null then
    10 insert into t_quotes values( L_tpnumber, rec.route_1 );
    11 end if;
    12 if rec.route_2 is not null then
    13 insert into t_quotes values( L_tpnumber, rec.route_2 );
    14 end if;
    15 if rec.route_3 is not null then
    16 insert into t_quotes values( L_tpnumber, rec.route_3 );
    17 end if;
    18 if rec.route_4 is not null then
    19 insert into t_quotes values( L_tpnumber, rec.route_4 );
    20 end if;
    21 if rec.route_5 is not null then
    22 insert into t_quotes values( L_tpnumber, rec.route_5 );
    23 end if;
    24 end loop;
    25 end;
    26 /
    PL/SQL procedure successfully completed.
    SQL> select tpnumber, routes from t_quotes;
    TPNUMBER ROUTE
    1001 1
    1001 56W
    1001 18
    1002 2
    1002 16
    1002 186
    1002 28
    7 rows selected.

  • Concatenate strings from more rows into one row.

    Hi,
    what's the name of that analytical function (or connect by) that
    would return strings from more rows as one row concatenated. i.e.:
    (I know this is possible using regular pipelined functions.)
    ROW1:   STR1
    ROW2:   STR2
    ROW3:   STR3
    select tadah().... from ...
    result:
    ROW1: STR1 STR2 STR3Thanks.

    Hi,
    Here's a basic example of SYS_CONNECT_BY_PATH.
    The query below produces one row of output per department, containing a list of the employees in that department, in alphabetioc order.
    WITH     got_rnum     AS
         SELECT     ename
         ,     deptno
         ,     ROW_NUMBER () OVER ( PARTITION BY  deptno
                                         ORDER BY          ename
                              ) AS rnum
         FROM     scott.emp
    --     WHERE     ...          -- Any filtering goes here
    SELECT     deptno
    ,     LTRIM ( SYS_CONNECT_BY_PATH ( ename
                                  , ','     -- Delimiter, must never occur in ename
               )          AS ename_list
    FROM     got_rnum
    WHERE     CONNECT_BY_ISLEAF     = 1
    START WITH     rnum          = 1
    CONNECT BY     rnum          = PRIOR rnum + 1
         AND     deptno          = PRIOR deptno
    ;Output:
    .   DEPTNO ENAME_LIST
            10 CLARK,KING,MILLER
            20 ADAMS,FORD,JONES,SCOTT,SMITH
            30 ALLEN,BLAKE,JAMES,MARTIN,TURNER,WARDThe basic CONNECT BY query would produce one row per employee, for example:
    .   DEPTNO ENAME_LIST
            10 ,CLARK
            10 ,CLARK,KING
            10 ,CLARK,KING,MILLER
            20 ,ADAMS
            20 ,ADAMS,FORD
    ...The WHERE clause: <tt>WHERE CONNECT_BY_ISLEAF = 1</tt> means that we'll only see the last row for every department.
    SYS_CONNECT_BY_PATH (which is a row function, by the way, not an analytic fucntion) puts a delimiter (',' in the example above) before every item on the list, including the first one.
    The query above uses LTRIM to remove the delimiter at the very beginning.
    WM_COMCAT (or the equivalent user-defined STRAGG, which you can copy from AskTom) is much more convenient if order is not important.

Maybe you are looking for