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.

Similar Messages

  • Parsing csv values into multiple rows ( URGENT )

    Hi All,
    I am having source table with below listed data set.
    EMPID ADD
    101 Chennai,Tamilnadu,India
    102 Delhi,India
    103 6th Street,Downst,CY,USA
    I need to create a View with below data format
    EMPID ADD
    101 Chennai
    101 Tamilnadu
    101 India
    102 Delhi
    102 India
    103 6th Street
    103 Downst
    103 CY
    103 USA
    I need SQL query ....as I dont have previllages to create PL/SQL :-(
    Please help me in this reagrd..
    Thanks in advance...
    Regards,
    Shiva

    user11938787 wrote:
    Hi...
    above links deals with how to handle csv files using SQL SERVER...
    I need to know about Oracle only...
    I knew that the link is for SQL Server but i think you don't need to know about Oracle only, you need to know about how to do it only, I mean the logic.
    Once you get the logic, it's quite simple to adapt it to Oracle.
    WITH tally AS ( SELECT LEVEL AS ID
                    FROM dual
                    CONNECT BY LEVEL <= 4000   
         emp  AS  (
                    SELECT 101 AS EMPID, 'Chennai,Tamilnadu,India' AS AD FROM dual
                    UNION ALL
                    SELECT 102 AS EMPID, 'Delhi,India' AS AD FROM dual
                    UNION ALL
                    SELECT 103 AS EMPID, '6th Street,Downst,CY,USA' AS AD FROM dual
    SELECT EMPID, AD
    FROM (             
            SELECT EMPID
                   ,NULLIF(substr(',' || AD || ',' , ID , instr(',' || AD || ',' , ','   , ID) - ID) , '') AS AD
                   ,ID
            FROM   Tally
                   ,emp
            WHERE  ID <= length(',' || AD || ',') AND substr(',' || AD || ',' , ID - 1, 1) = ','
            AND    instr(',' || AD || ',', ','   , ID) - ID > 0
            ORDER BY EMPID, ID
          )Regards...

  • Need to convert values into coma separated

    Need to convert values into coma separated
    I have a string value that stores data like 'NYK,IND,SGP,GER'
    FOR EXAMPLE
    V_CITY_CODE = 'NYK,IND,SGP,GER'
    When I query
    select * from city where city_code = V_CITY_CODE;I get no rows, this is because V_CITY_CODE has all city code as single code.
    I need a function to search , and replace with ','.
    I tried using instr and replace but was unable to convert it.
    could some one pls assist me.
    thanks in advance
    Saz

    Looking for this?
    SQL> select * from emp
      2  /
         EMPNO     DEPTNO ENAME                                 SAL DOJ       JOB
             1          1 Karthick                               80 03-DEC-11
             2          1 Karthick_1                             90 23-NOV-11
             3          2 Ram                                    80 03-DEC-11
             4          2 Ram_1                                  90 23-NOV-11
    SQL> var v_ename varchar2(1000)
    SQL> exec :v_ename := 'Karthick,Karthick_1'
    PL/SQL procedure successfully completed.
    SQL> select *
      2    from emp
      3   where ename in (
      4                     select regexp_substr(val, '[^,]+', 1, level)
      5                        from (select :v_ename val from dual)
      6                    connect by level <= length(val) - length(replace(val, ','))+1
      7                  ) 
      8  /
         EMPNO     DEPTNO ENAME                                 SAL DOJ       JOB
             1          1 Karthick                               80 03-DEC-11
             2          1 Karthick_1                             90 23-NOV-11

  • I need to divide selected row into multiple rows when i navigate  ADF 11g

    Hi
    I'm using jdeveloper 11.1.1.2.0 with ADF 11g.
    I need to divide selected row into multiple rows when i navigate to other page . Scenario - in first page i'm displaying some records with columns like empno , empstatus , empworkdepts ,curdepts
    Here empworkdepts gives the numeric number like no of departments work shifts 3 or 4 or 5. when i select any particular employee and fire next button to navigate next page.I have to divide the selected employee with same information into multiple times based on the empworkdepts value.
    empno empstatus empworkdepts curdept
    001 eds 2 TS
    002 hr 1 FO
    003 eds 4 TS
    *004 eds 3 TS*
    now i selected employee 004 , when i navigate to next page.
    Empno EmpStatus EmpWorkDepts CurDept
    004 eds 3 TS
    004 eds 3 TS
    004 eds 3 TS
    i did with java code in bean .but not stable .
    any help............
    thanks advance.............
    Edited by: user9010551 on May 5, 2010 10:48 PM
    Edited by: user9010551 on May 10, 2010 11:31 PM

    user9086775 wrote:
    Hi Experts,
    I have a requirment where i need to fetch parts of a single row into multiple rows from a singlt Query, i am sure it is possible using Pivots but just cant figure out an approach. Any help on this is highly appriciapted.
    Requirment:
    This is a sample set record in a table
    Product     Sub Product          Name    Age
    New Car    Nissan                   Tom        49
    New Car    Nissan                   Jack         36
    Old Car      Audi                     Sam         24
    Old Car      Jaguar                  Pint          26
    Old Car      Audi                     Smith       41
    I need to be able to fetch the above data in the below fashion
    Product     Sub Product          Name    Age
    New Car
    Nissan
    Tom        49
    Jack        36
    Old Car     
    Audi            
    Sam        24
    Smith      41
    Jaguar                   Pint         26Please help with ideas as to how can i achive the above without using PLSQL.
    Thanks in advance!You should be doing this in the client on not in the DB. Use the reporting tool that you use to do this.
    For example if you are in SQL Plus you can use the BREAK command.

  • How To Concatenate Column Values from Multiple Rows into a Single Column?

    How do I create a SQL query that will concatenate column values from multiple rows into a single column?
    Last First Code
    Lesand Danny 1
    Lesand Danny 2
    Lesand Danny 3
    Benedi Eric 7
    Benedi Eric 14
    Result should look like:
    Last First Codes
    Lesand Danny 1,2,3
    Benedi Eric 7,14
    Thanks,
    David Johnson

    Starting with Oracle 9i
    select last, first, substr(max(sys_connect_by_path(code,',')),2) codes
    from
    (select last, first, code, row_number() over(partition by last, first order by code) rn
    from a)
    connect by last = prior last and first = prior first and prior rn = rn -1
    start with rn = 1
    group by last, first
    LAST       FIRST      CODES                                                                                                                                                                                                  
    Lesand         Danny          1,2,3
    Benedi         Eric           7,14Regards
    Dmytro

  • To display comma separted value into multiple column

    Hi,
    I want to display value into multiple column like below
    data is like this
    col1
    res_menaHome:MenaHome
    res_menaHomeEmp:MenaHome Employee
    res_MDSpecialSer:MD Special Services
    res_Smart:Smart
    now i want to display like
    col1 col2
    res_menaHome MenaHome
    res_menaHomeEmp MenaHome Employee
    res_MDSpecialSer MD Special Services
    res_Smart Smart
    Thanks in advance.

    You mean like this?
    with q as (select 'res_menaHome:MenaHome' myString from dual)
    select substr(myString, 1, instr(myString, ':') - 1) col1,
    substr(myString, instr(myString, ':') + 1) col2
    from q
    COL1,COL2
    res_menaHome,MenaHome

  • Splitting comma seperated column data into multiple rows

    Hi Gurus,
    Please help me for solving below scenario. I have multiple value in single column with comma seperated values and my requirement is load that data into multiple rows.
    Below is the example:
    Source Data:
    Product         Size                                 Stock
    ABC              X,XL,XXL,M,L,S                 1,2,3,4,5,6
    Target Data:
    Product         Size                                 Stock
    ABC              X                                     1
    ABC              XL                                   2
    ABC              XXL                                 3
    ABC              M                                    4
    ABC              L                                      5
    ABC             S                                        6
    Which transformation we need to use for getting this output?
    Thanks in advance !

    Hello,
    Do you need to do this tranformation through OWB mapping only? And can you please tell what type of source you are using? Is it a flat file or a table?
    Thanks

  • Concatenate a column value across multiple rows - PDW

    We are using PDW based on SQL2014. We require an efficient logic on how to concatenate a column value across multiple rows. We have the following table
    T1
    (CompanyID, StateCD)
    Having following rows:
    1              NY
    1              NJ
    1              CT
    2              MA
    2              NJ
    2              VA
    3              FL
    3              CA
    We need a code snippet which will return following result set:
    1                    
    CT,NJ,NY
    2                    
    MA,NJ,VA
    3                    
    CA,FL
    We have tried built-in function STUFF with FOR XML PATH clause and it is not supported in PDW. So, we need a fast alternative.

    Hi Try this:
    SELECT * INTO #ABC
    FROM 
    SELECT 1 AS ID,'NY' AS NAME
    UNION 
    SELECT 1 AS ID,'NJ' AS NAME
    UNION 
    SELECT 1 AS ID,'CT' AS NAME
    UNION 
    SELECT 2 AS ID,'MA' AS NAME
    UNION 
    SELECT 2 AS ID,'NJ' AS NAME
    UNION 
    SELECT 2 AS ID,'VA' AS NAME
    UNION 
    SELECT 3 AS ID,'FL' AS NAME
    UNION 
    SELECT 3 AS ID,'CA' AS NAME
    )A
    CREATE TABLE ##CDB (ID INT, NAME NVARCHAR(800)) 
    DECLARE @TMP VARCHAR(MAX), 
            @V_MIN INT,
    @V_MAX INT,
    @V_COUNT INT
    SELECT @V_MIN=MIN(ID),@V_MAX=MAX(ID) FROM #ABC 
    SET @V_COUNT=@V_MIN
    WHILE @V_COUNT<=@V_MAX
    BEGIN
    SET @TMP = '' SELECT @TMP = @TMP + CONVERT(VARCHAR,NAME) + ', ' FROM #ABC 
    WHERE ID=@V_COUNT
    INSERT INTO ##CDB (ID, NAME) SELECT @V_COUNT AS ID ,CAST(SUBSTRING(@TMP, 0, LEN(@TMP)) AS VARCHAR(8000)) AS NAME 
    SET @V_COUNT=@V_COUNT+1
    END
    SELECT * FROM ##CDB
    OR
    SELECT * INTO #ABC
    FROM 
    SELECT 1 AS ID,'NY' AS NAME
    UNION 
    SELECT 1 AS ID,'NJ' AS NAME
    UNION 
    SELECT 1 AS ID,'CT' AS NAME
    UNION 
    SELECT 2 AS ID,'MA' AS NAME
    UNION 
    SELECT 2 AS ID,'NJ' AS NAME
    UNION 
    SELECT 2 AS ID,'VA' AS NAME
    UNION 
    SELECT 3 AS ID,'FL' AS NAME
    UNION 
    SELECT 3 AS ID,'CA' AS NAME
    UNION 
    SELECT 5 AS ID,'LG' AS NAME
    UNION 
    SELECT 5 AS ID,'AP' AS NAME
    )A
    CREATE TABLE ##CDB (ID INT, NAME NVARCHAR(800)) 
    DECLARE @TMP VARCHAR(MAX), 
            @V_MIN INT,
    @V_MAX INT,
    @V_COUNT INT
    SELECT @V_MIN=MIN(ID),@V_MAX=MAX(ID) FROM #ABC 
    SET @V_COUNT=@V_MIN
    WHILE @V_COUNT<=@V_MAX
    BEGIN
    SET @TMP = '' SELECT @TMP = @TMP + CONVERT(VARCHAR,NAME) + ', ' FROM #ABC 
    WHERE ID=@V_COUNT
    SELECT @V_COUNT AS ID ,CAST(SUBSTRING(@TMP, 0, LEN(@TMP)) AS VARCHAR(8000)) AS NAME INTO #TEMP 
    INSERT INTO ##CDB (ID, NAME) SELECT ID, NAME FROM #TEMP WHERE NAME<>''
    DROP TABLE #TEMP
    SET @V_COUNT=@V_COUNT+1
    END
    SELECT * FROM ##CDB
    Thanks Shiven:) If Answer is Helpful, Please Vote

  • Urgent: How to break 1 Row into Multiple Rows

    Hi Experts,
    I have a requirment where i need to fetch parts of a single row into multiple rows from a singlt Query, i am sure it is possible using Pivots but just cant figure out an approach. Any help on this is highly appriciapted.
    Requirment:
    This is a sample set record in a table
    Product Sub Product Name Age
    New Car Nissan Tom 49
    New Car Nissan Jack 36
    Old Car Audi Sam 24
    Old Car Jaguar Pint 26
    Old Car Audi Smith 41
    I need to be able to fetch the above data in the below fashion
    Product Sub Product Name Age
    New Car
    Nissan
    Tom 49
    Jack 36
    Old Car
    Audi
    Sam 24
    Smith 41
    Jaguar Pint 26
    Please help with ideas as to how can i achive the above without using PLSQL.
    Thanks in advance!

    user9086775 wrote:
    Hi Experts,
    I have a requirment where i need to fetch parts of a single row into multiple rows from a singlt Query, i am sure it is possible using Pivots but just cant figure out an approach. Any help on this is highly appriciapted.
    Requirment:
    This is a sample set record in a table
    Product     Sub Product          Name    Age
    New Car    Nissan                   Tom        49
    New Car    Nissan                   Jack         36
    Old Car      Audi                     Sam         24
    Old Car      Jaguar                  Pint          26
    Old Car      Audi                     Smith       41
    I need to be able to fetch the above data in the below fashion
    Product     Sub Product          Name    Age
    New Car
    Nissan
    Tom        49
    Jack        36
    Old Car     
    Audi            
    Sam        24
    Smith      41
    Jaguar                   Pint         26Please help with ideas as to how can i achive the above without using PLSQL.
    Thanks in advance!You should be doing this in the client on not in the DB. Use the reporting tool that you use to do this.
    For example if you are in SQL Plus you can use the BREAK command.

  • Reg : Concatenation of a column value with multiple rows... URGENT

    Hello,
    Could any of u help me in concatenating a column value with
    multiple rows ???
    For ex : I've the following data from emp table :
    DEPTNO ENAME
    10 KING'S
    30 BLAKE
    10 CLARK
    10 TOM JONES
    30 ALLEN
    30 JAMES
    20 SMITH
    20 SCOTT
    20 MILLER
    10 MILLER
    20 rajeev
    I want the following output :
    deptno Concat_value
    10 KING'S,CLARK,TOM JONES,MILLER
    20 Rajeev,MILLER,SMITH,SCOTT
    30 BLAKE,ALLEN,JAMES
    Thanks in Advance,
    Srini

    Hello Naveen,
    Thanks for ur answer. But I need a single SQL query for getting
    what I want. I know the solution in PL/SQL.
    Please try it in a single SQL....
    Thanks again,
    Srini

  • Cats ESS view - into multiple rows when we release times or refresh them

    Dear ALL,
    We are using the record working times and when we enter the data for the week for 5 days each with 8 hours a day in one row in portal. Once we refresh or review that page it is resulting into multiple rows, like for 5 days five rows each row containing an entry for each day. how can we avoid this, we want all entries maintained into one row only.
    Help is appreciated.
    Thanks and Regs,
    Raj

    Made some changes in Data entry profiles

  • Easy Question: How to split concatenated string into multiple rows?

    Hi folks,
    this might be an easy question.
    How can I split a concatenated string into multiple rows using SQL query?
    INPUT:
    select 'AAA,BBB,CC,DDDD' as data from dualDelimiter = ','
    Expected output:
    data
    AAA
    BBB
    CCC
    DDDDI'm looking for something kind of "an opposite for 'sys_connect_by_path'" function.
    Thanks,
    Tomas

    Here is the SUBSTR/INSTR version of the solution:
    SQL> WITH test_data AS
      2  (
      3          SELECT ',' || 'AAA,BBB,CC,DDDD' || ',' AS DATA FROM DUAL
      4  )
      5  SELECT  SUBSTR
      6          (
      7                  DATA
      8          ,       INSTR
      9                  (
    10                          DATA
    11                  ,       ','
    12                  ,       1
    13                  ,       LEVEL
    14                  ) + 1
    15          ,       INSTR
    16                  (
    17                          DATA
    18                  ,       ','
    19                  ,       1
    20                  ,       LEVEL + 1
    21                  ) -
    22                  INSTR
    23                  (
    24                          DATA
    25                  ,       ','
    26                  ,       1
    27                  ,       LEVEL
    28                  ) - 1
    29          )       AS NEW_STRING
    30  FROM    test_data
    31  CONNECT BY LEVEL <= LENGTH(REGEXP_REPLACE(DATA,'[^,]','')) - 1
    32  /
    NEW_STRING
    AAA
    BBB
    CC
    DDDD

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

  • Need to insert values into a table from a XML file

    Hi,
    I'm an Oracle 9i/10g DBA with quite a few years experience, but I'm new to XML and dealing with it in database terms. I've been given a project that entails pulling XML values out of a file (or 100's of them) and storing them in the database so that they are searchable by end-users. The project is classified as secret so I'm unable to upload the specific XML or any info relating to the structire of the XML or the table I will use to insert the values into - sorry!! So, I've created an XML file with a similar structure to help people understand my predicament.
    The end-users only need to search on a subset of the total amount of columns from the table I'll insert data into, although the XML file has a lot more, so I dont need to store the other values - but I will need to store the name of the XML file (or a pointer to it so I know what XML file a particular set of values belong to) in another column of the table along with its associated values.
    I've been using the XMLTABLE function with some degree of success, although I had better succes using the XMLSEQUENCE function. However, I found out this is deprecated in 10g and replaced with XMLTABLE, so I guess it's better if I use this in case we ever need to upgrade to 11g.
    The main problem I've been having is that some elements in the XML files have multiple values for the one record when all the other records are the same. In terms of storing this in the database, I guess it would mean inserting multiple rows in the table for each element where the value differs. Here is a dumbed down XML file similar to what I've got along with the other SQL I've used:
    +<?xml version="1.0" encoding="UTF-8"?>+
    +<House>+
    +<Warehouse>+
    +<WarehouseId>1</WarehouseId>+
    +<WarehouseName>+
    +<Town>Southlake</Town>+
    +<State>Texas</State>+
    +</WarehouseName>+
    +<Building>Owned</Building>+
    +<Area>25000</Area>+
    +<Docks>2</Docks>+
    +<DockType>Rear load</DockType>+
    +<WaterAccess>true</WaterAccess>+
    +<RailAccess>N</RailAccess>+
    +<Parking>Street</Parking>+
    +<VClearance>10</VClearance>+
    +</Warehouse>+
    +<Warehouse>+
    +<WarehouseId>2</WarehouseId>+
    +<WarehouseName>+
    +<Town>Poole</Town>+
    +<State>Dorset</State>+
    +</WarehouseName>+
    +<WarehouseName>+
    +<Town>Solihull</Town>+
    +<County>West Midlands</State>+
    +</WarehouseName>+
    +<Building>Owned</Building>+
    +<Area>40000</Area>+
    +<Docks>5</Docks>+
    +<DockType>Rear load</DockType>+
    +<WaterAccess>true</WaterAccess>+
    +<RailAccess>N</RailAccess>+
    +<Parking>Bay</Parking>+
    +<VClearance>10</VClearance>+
    +</Warehouse>+
    +<Warehouse>+
    +<WarehouseId>3</WarehouseId>+
    +<WarehouseName>+
    +<Town>Fleet</Town>+
    +<County>Hampshire</County>+
    +</WarehouseName>+
    +<Building>Owned</Building>+
    +<Area>10000</Area>+
    +<Docks>1</Docks>+
    +<DockType>Side load</DockType>+
    +<WaterAccess>false</WaterAccess>+
    +<RailAccess>N</RailAccess>+
    +<Parking>Bay</Parking>+
    +<VClearance>20</VClearance>+
    +</Warehouse>+
    +</House>+
    CREATE TABLE xmltest OF XMLTYPE;
    INSERT INTO xmltest
    VALUES(xmltype(bfilename('XML_DIR', 'test.xml'), nls_charset_id('AL32UTF8')));
    Consequently, I need to...
    1) Retrieve the results from the XML file for all 3 warehouses where multiple values for the same sub-element are shown as 2 rowsthe result set. (I am guessing there will be 4 rows returned as warehouse sub-2 has 2 different elements for <WarehouseName>.
    2) Build a case statement into the query so that regardless of the sub-element name (i.e State or County), it is returned into the 1 column, for instance County.
    So, if I run a query similar to the following...
    select y.WarehouseId, y.Town, y.County, y.Area
    from xmltest x, xmltable('/House/Warehouse' .......
    I would like to get results back like this...
    ID Town County Area
    1 Southlake Texas 25000
    2 Poole Dorset 40000
    2 Solihull West Midlands 40000
    3 Fleet hampshire 10000
    Sorry for the non-formatting but I hope this all makessense to someone out there with what I'm trying to do.
    I appreciate any help whatsoever because, as i said before, I'm totally new to XML and trying to read the vast amount of information there is out there on XML is all a bit daunting.
    Many thanks in advance,
    Shaun.

    Hi again,
    Thanks for keeping the post open for me. I've had a look at the post illustrating the XFileHandler package, and tried to alter it to make it fit with my XML files. To help explain things, my XML file looks like this:
    <?xml version="1.0"?>
    <!DOCTYPE  CMF_Doc SYSTEM "CMF_Doc.dtd">
    <House>
        <Warehouse>
        <WarehouseId>1</WarehouseId>
        <WarehouseName>
           <Town>Southlake</Town>
           <State>Texas</State>
        </WarehouseName>
        <Building>Owned</Building>
        <Area>25000</Area>
        <Docks>2</Docks>
        <DockType>Rear load</DockType>
        <WaterAccess>true</WaterAccess>
        <RailAccess>N</RailAccess>
        <Parking>Street</Parking>
        <VClearance>10</VClearance>
      </Warehouse>
      <Warehouse>House
        <WarehouseId>2</WarehouseId>
        <WarehouseName>
           <Town>Poole</Town>
           <State>Dorset</State>
        </WarehouseName>
        <WarehouseName>
           <Town>Solihull</Town>
           <County>West Midlands</County>
        </WarehouseName>
        <Building>Owned</Building>
        <Area>40000</Area>
        <Docks>5</Docks>
        <DockType>Rear load</DockType>
        <WaterAccess>true</WaterAccess>
        <RailAccess>N</RailAccess>
        <Parking>Bay</Parking>
        <VClearance>10</VClearance>
      </Warehouse>
      <Warehouse>
        <WarehouseId>3</WarehouseId>
        <WarehouseName>
           <Town>Fleet</Town>
           <County>Hampshire</County>
        </WarehouseName>
        <Building>Owned</Building>
        <Area>10000</Area>
        <Docks>1</Docks>
        <DockType>Side load</DockType>
        <WaterAccess>false</WaterAccess>
        <RailAccess>N</RailAccess>
        <Parking>Bay</Parking>
        <VClearance>20</VClearance>
      </Warehouse>
    </House>
    <?xml version="1.0" encoding="UTF-8"?>
    <House>
        <Warehouse>
        <WarehouseId>4</WarehouseId>
        <WarehouseName>
           <Town>Dallas</Town>
           <State>Texas</State>
        </WarehouseName>
        <Building>Owned</Building>
        <Area>25000</Area>
        <Docks>2</Docks>
        <DockType>Rear load</DockType>
        <WaterAccess>true</WaterAccess>
        <RailAccess>N</RailAccess>
        <Parking>Street</Parking>
        <VClearance>10</VClearance>
      </Warehouse>
      <Warehouse>
        <WarehouseId>5</WarehouseId>
        <WarehouseName>
           <Town>Dorchester</Town>
           <State>Dorset</State>
        </WarehouseName>
        <WarehouseName>
           <Town>Solihull</Town>
           <County>West Midlands</County>
        </WarehouseName>
        <Building>Owned</Building>
        <Area>40000</Area>
        <Docks>5</Docks>
        <DockType>Rear load</DockType>
        <WaterAccess>true</WaterAccess>
        <RailAccess>N</RailAccess>
        <Parking>Bay</Parking>
        <VClearance>10</VClearance>
      </Warehouse>
      <Warehouse>
        <WarehouseId>6</WarehouseId>
        <WarehouseName>
           <Town>Farnborough</Town>
           <County>Hampshire</County>
        </WarehouseName>
        <Building>Owned</Building>
        <Area>10000</Area>
        <Docks>1</Docks>
        <DockType>Side load</DockType>
        <WaterAccess>false</WaterAccess>
        <RailAccess>N</RailAccess>
        <Parking>Bay</Parking>
        <VClearance>20</VClearance>
      </Warehouse>
    </House>
    <?xml version="1.0" encoding="UTF-8"?>
    <House>
        <Warehouse>
        <WarehouseId>7</WarehouseId>
        <WarehouseName>
           <Town>Southlake</Town>
           <State>Texas</State>
        </WarehouseName>
        <Building>Owned</Building>
        <Area>25000</Area>
        <Docks>2</Docks>
        <DockType>Rear load</DockType>
        <WaterAccess>true</WaterAccess>
        <RailAccess>N</RailAccess>
        <Parking>Street</Parking>
        <VClearance>10</VClearance>
      </Warehouse>
      <Warehouse>
        <WarehouseId>8</WarehouseId>
        <WarehouseName>
           <Town>Bournemouth</Town>
           <State>Dorset</State>
        </WarehouseName>
        <WarehouseName>
           <Town>Shirley</Town>
           <County>West Midlands</County>
        </WarehouseName>
        <Building>Owned</Building>
        <Area>30000</Area>
        <Docks>5</Docks>
        <DockType>Rear load</DockType>
        <WaterAccess>true</WaterAccess>
        <RailAccess>N</RailAccess>
        <Parking>Bay</Parking>
        <VClearance>10</VClearance>
      </Warehouse>
      <Warehouse>
        <WarehouseId>9</WarehouseId>
        <WarehouseName>
           <Town>Clapham</Town>
           <County>London</County>
        </WarehouseName>
        <Building>Owned</Building>
        <Area>10000</Area>
        <Docks>1</Docks>
        <DockType>Side load</DockType>
        <WaterAccess>false</WaterAccess>
        <RailAccess>N</RailAccess>
        <Parking>Bay</Parking>
        <VClearance>20</VClearance>
      </Warehouse>
    </House>And the XFilehandler package looks like this (I'm just trying to do a simple select only on WarehouseId & WaterAccess for the time being to keep things simple):
    create or replace package XFileHandler as
      TYPE TRECORD IS RECORD (
        WID     NUMBER(2)
      , WACCESS VARCHAR2(5)
      type TRecordTable is table of TRecord;
      function getRows (p_directory in varchar2, p_filename in varchar2) return TRecordTable pipelined;
    end;
    create or replace package body XFileHandler is
      function getRows (p_directory in varchar2, p_filename in varchar2)
       return TRecordTable pipelined
      is
        nb_rec          number := 1;
        tmp_xml        clob;
        tmp_file         clob;
        rec               TRecord;
      begin
        DBMS_LOB.CREATETEMPORARY(TMP_FILE, TRUE);
        tmp_file := dbms_xslprocessor.read2clob(p_directory, p_filename);
        LOOP
          tmp_xml := regexp_substr(tmp_file, '<\?xml[^?]+\?>\s*<([^>]+)>.*?</\1>', 1, nb_rec, 'n');
          exit when length(tmp_xml) = 0;
          --dbms_output.put_line(tmp_rec);
          nb_rec := nb_rec + 1;
        select y.WID, y.WACCESS
        into rec.WID, rec.WACCESS
        from xmltable('/House' passing xmltype(tmp_xml)
                      columns WID NUMBER(2) PATH 'Warehouse/WarehouseId',
                                  WACCESS VARCHAR2(5) PATH 'WaterAccess') y;
          pipe row ( rec );
        end loop;
        dbms_lob.freetemporary(tmp_file);
        return;
      end;
    end;Now, when I run the query:
    select * from table(XFileHandler.getRows('XML_DIR', 'XFileHandler_test.xml'));I get the error: ORA-00600: internal error code, arguments: [17285], [0x5CFE8DC8], [4], [0x45ABE1C8], [], [], [], []
    I had a look in the dump file for anything obvious, but nothing really stands out. Is there anything obvious in my code that I'm missing or something else which you may think could be causing this error, e.g in the regular expression regexp_substr?
    Many thanks,
    Shaun.

  • Importing CSV files into Multiple Tables in One Database

     I have a web based solution using Microsoft SharePoint and SQL Server that is created to centralize dat collection and reporting of program metrics used in montly reviews.
    A person from each program enters dat manual or by pushing the data using automated data import tools. The user then is able to generate reports and provide presentations to their stakeholders.
    There are are programs that are located in US and 2 that are located in Japan. All, including programs in Japan use the MS Project with a plug-in tool that allows them to auto input data. When the user click the "Send To.." button, the data goes
    in to multiple tables in one database.
    Everything is set up exactly the same for every program; however, we have discovered becase of a firewall, along with some of the different settings that the MS Project has over in Japan, the 2 program users are not able to auto import their data.
    The suggestion is to have the program users export the MS Project file into a CSV and email it. I will then take it and convert the data, such as the dates and place them on a Network Drive. There will be 2 folders, one for each program.
    I feel it will be an easy process just to load the data from the Network Drive into the same tables that are created for auto import.
    My Concerns/Questions:
    1. Should I create 1 SSIS package or should there be 2, one for each program?
    2. US and Japan program users send their data once a month. The converted files are going to be saved in the location marked with a date (ex:201402). How can i have it to where SSIS will automatically load the data every time i place new files in the designated
    folders or when i update an exsisting file?
    Can you provide an example with your suggestion please?
    I greatly appreciate the assistance!
    Y_Tyler

    Hello Vikash,
    Thank you! This will help me get started.
    There will be 2 folders, one with files with Program A data and the other with files with Program B data. All will have the same fields, just coming from different programs. You stated that I will be able to to load both in one package. Would there be two
    paths since there will be two separate folders?
    Using the example you provided, i am confident that I can create the package using one path into one table but not sure how to get the files from 2 paths (if there is) into multiple tables.
    Can you help clarify this for me?
    Thank you!
    Y_Tyler

Maybe you are looking for

  • How to restrict Option values for a particular metadata in profile checkin

    How to restrict Option values (drop down) for a particular metadata in profile checkin- Metadata field Color is having options dropdown values (stored in table/views)- Display name - Blue, Value=1 Display name - Red, Value=2 Display name - Yellow, Va

  • IPad AIR bought in USA - use in Germany with t-online SIM?

    My business partner in USA provide a new iPad AIR - either WLAN only or WLAN plus cellular. Is it possible to use an iPad AIR, which was bought in USA together, with a German SIM-card from "T-MOBIL/TELEKOM Germany"? I am wondering, if this works! Hei

  • Keyboard shortcut for cropping (Acrobat XI)

    Hi. I have a minor question about the cropping feature in Acrobat XI. In the previous version (X), the keyboard shortcut for crooping PDF pages is Ctrl+Shift+T. However, when I try this combination in the new XI version, it brings up a dialog asking

  • Chinese language support in WDP

    Hi I want to pick up the Chinese characters from database and show it on WDP UI. On UI it all shows as junk characters.... How can I enable my WDP Application to show the Chinese characters correctly... Regards

  • Red Eye removal - Green Eye removal

    My subjects are mostly people on horses, and sometimes red eye removal is necessary and works fine. However, horses (as well as most other animals) have a differently colored retina, so I'd need a Green Eye Removal. Would it be possible to make the R