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.

Similar Messages

  • How to split one request into many to reduce response time

    Hi,
    In a request I may get more than 20-30 materials for which, pricing info need to be returned. Its increasing the load on SAP and XI is not waiting for a long time to get the price. Please let me know a work around for this otherthan BPM.
    Or is there any mechanism by which I can split the XML into multiple XMLs and process multi small requests.
    Thanks
    Seshu

    Hi Seshu -
    Timeouts can be tricky in synchronous cases with all the various components of XI.  In your case, you've implied that the RFC receiver adapter is being used to talk to SAP and it's taking a long time for SAP to process this request and send back a response.  Are you getting a '...MessageExpiredException'?  If so, the parameter 'xiadapter.inbound.timeout.default' in the 'SAP XI Adapter: XI' J2EE service would be relevant (see Note 791379 for details).  The 'syncMessageDeliveryTimeoutMsec' parameter of the 'SAP XI Adapter: RFC' J2EE service is only relevant if you're using the RFC sender adapter.
    Other timeout settings may come into play.  <a href="http://service.sap.com/~sapidb/011000358700005909032005E/XI30XI70_TroubleGuide.pdf">The XI Troubleshooting guide</a> has some good information on this.
    Also, if this scenario is required to be synchronous, there's no way to split the request without using BPM as synchronous requests cannot be sent to multiple receivers.
    Regards,
    Jin

  • How to split one page into different frames in ADF?

    Hi,
    Can any one please guide me how to split a jspx into different frames.
    i.e., left frame contains <af:panelSideBar> which contains multiple <af:commandMenuItem> s. And whenver we click on the one <af:commandMenuItem>, it has to show the corresponing page inside center frame in this page itself. Is it possible in ADF? Which component we need to use?
    Can anyone guide me on this?
    Thanks in advance,
    Regards,
    Suresh Kethireddy

    You can use a combination of the ADF Faces 10.1.3 components like:
    af:panelPage
    af:panelSideBar
    af:panelHorizontal
    af:panelGroup
    to organize the screen layout, but it is not the interactive splitter that the 11g product provides.
    You can all all the 10.1.3 ADF Faces Components here:
    http://www.oracle.com/technology/products/jdev/htdocs/partners/addins/exchange/jsf/doc/tagdoc/core/imageIndex.html

  • Please help with an sql to show more than one records into single row for each student

    From the following data I would like to create an sql to get the information  as the following layout
    studentid,  firstTerm,  EnglishMark1,ScienceMark1,MathsMark1, Secondterm,EnglishMark2,ScienceMark2,MathsMark2,
    ThirdTerm,EnglishMark3,ScienceMark3,MathsMark3 // As single rows for each student
    Example
    1 First, 30,40,20,Sec,30,40,20,  simillarly next row for next row for another sudent. Please help to generate the sql for the same.
    Please help it would be very appreciate.
    With Thanks
    Pol
    polachan

    create table yourdata (studentid int, term varchar(10), section varchar(50), Mark int)
    insert into yourdata values
    (1,'First','Math',20),(1,'First','English',30),(1,'First','Science',40),
    (2,'First','Math',20),(2,'First','English',30),(2,'First','Science',40),
    (3,'First','Math',20),(3,'First','English',30),(3,'First','Science',40),
    (1,'Sec','Math',20),(1,'Sec','English',30),(1,'Sec','Science',40),
    (2,'Sec','Math',20),(2,'Sec','English',30),(2,'Sec','Science',40),
    (3,'Sec','Math',20),(3,'Sec','English',30),(3,'Sec','Science',40)
    Select studentid
    ,max(case when term='First' and section='English' Then Mark End) as EnglishMark1
    ,max(case when term='First' and section='Science' Then Mark End) as ScienceMark1
    ,max(case when term='First' and section='Math' Then Mark End) as MathMark1
    ,max(case when term='Sec' and section='English' Then Mark End) as EnglishMark2
    ,max(case when term='Sec' and section='Science' Then Mark End) as ScienceMark2
    ,max(case when term='Sec' and section='Math' Then Mark End) as MathMark2
    ,max(case when term='Third' and section='English' Then Mark End) as EnglishMark3
    ,max(case when term='Third' and section='Science' Then Mark End) as ScienceMark3
    ,max(case when term='Third' and section='Math' Then Mark End) as MathMark3
    From yourdata
    Group by studentid
    drop table yourdata

  • 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

  • PRE9: How to split one clip into two (or more) clips?

    I can't believe this is so hard to do... But HOW?

    You don't necessarily need to separate the file into individual clips.  When you do a cut on the timeline, this is a virtual cut, leaving the original file untouched but determining what will appear in the output.  You can split the clip into multiple pieces, delete the bits you don't want, add transitions, insert new bits, whatever you want, all without affecting the original file in any way.  Once you're happy, you output a new file using the Share options, and you get a new video file, with your original files still untouched.
    If you want to split your file into multiple individual files, you can use the sliders on the time scale, and export (Share) using the Share Work Area Only checkbox.  If you're doing this for purposes of reassembly, it would be better to save the individual clips in as lossless a format as possible, the default AVI format taking considerably more space but not losing quality.  Hint: the sliders can be positioned to the time marker using Alt-[ and Alt-].  Once you've done this, note that your original file will still be there, untouched.
    There is also VideoRedo Plus, a cheap program which gives frame-accurate selection and allows rapid subdivision of a piece of footage.  It doesn't re-render as PE9 would (this is where loss of image quality creeps in using compressed formats such as MPEG), copying the original frames.  You can then reassemble the bits using your video editor.

  • How to split one monitor into two, differently configured desktops

    Hello,
    I have a 27" iMac. I would like to split the screen into two differently configured desktops or monitors. Apps like TwoUp or Divy don't exactly do this. I'll explain it with an example:
    Suppose I'm working on a document and I need to open many folders to retrieve files. One common problem is that opened folders overlap each other and sometimes they overlap with the document I'm working on, or they go underneath the document. I would like to split the screen vertically in, say, two virtual, independent desktops/monitors, like this:
    - one window/space on one side (say, on the left) of the screen would contain the document  from top to bottom, with no dock bar on the bottom
    - the other window/space (right) would behave as a regular, full desktop, with the entire dock on the bottom
    In this way, if I need to navigate to find a file to use in the document, I would move the cursor to the right. The Finder would work only in this window/space, thus windows or other applications would never overlap or clutter the left side of the screen. Drag-and-drop from right to left should be possible.
    One way to imagine it is as if the 16x9 monitor were comprised by two vertical, 8x9 independent monitors side by side, each with its own configuration.
    Is this possible? Can anyone recommend an application or type of setup?
    Thank you,
    -celso

    Looking for something like this?
    You can tell Display Maid to save the positions of your open windows across many apps and later restore those positions when things become a mess. With Display Maid you don’t have to restore windows one at a time, or even one app at a time. Display Maid restores all saved window positions across all apps with one command. It will also restore window positions automatically when it detects a workspace change.
    http://www.funk-isoft.com/index.php/display-maid

  • How To Split One Record  into 30 Records(Number of days in a Month)

    Hi Experts,
      we are getting the montly(yearmonth) Forecast data from flat file we need to generate the report which shows the daily Forecast data,
    For example for the month of June Forecast we have  150EA.
    Flat file data is like this
      0calday    Qty
      201006     150
    we need to show the report like datawise
       Calday                                     Forecast qty
    20100601                                          5
    20100602                                          5
    20100603                                          5
    20100604                                          5
    20100605                                          5
    20100606                                          5
    20100630                                           5
    its like month forecast / Number of days in a month.
    we can achive these  in two ways as per my knowledge
    1. At the time loading data
    2. Reporting level
    Which is the best way
    how can we achive this.
    Thanks
    Chandra

    Hey.  There was a similar posting I gave a suggestion on a while back.  Here is the link...
    Re: Spliting records into cube
    As far as the correct time of doing this, I would definitely do this at the time of data load and not time of reporting. 
    Hope you find it helpful.
    Thanks

  • How to split one characteristic into 2 columns in query

    Hi,
    There is a characteristic TASK, which has a navigation attribute Phase Indicator, and if Phase Indicator = 1, then this Task is a Phase, or else it's a normal Task.
    Now I want to have a result with 2 columns like:
    Phase     Normal Task
    PH1        T1
    PH1        T2
    PH2        T3
    PH2        T4
    Could you give any advice on how to realize it?
    Thanks in advance!
    Regards,
    Napoleon

    Hi Napoleon,
    In ur query create 2 selections and give description as phase and normal task.
    In the 'phase' sleection drag 'task' as info object and give restriction for the nav attribute 'phase indicator' with 1.
    Similarly in the 'normal task' selection again drag 'task' as info object and give restriction for the nav attribute 'phase indicator' with not equal to 1.Hope it helps
    Regards,
    Rathy

  • How to SPLIT ONE STEREO TRACK'S L & R CHANNELS INTO TWO MONO CHANNELS

    Does anyone know if this is possible: How to SPLIT ONE STEREO TRACK'S L & R CHANNELS INTO TWO MONO CHANNELS?  There's got to be a way, but I just can't find out how.
    I recorded a podcast -- me and a guest, with each mic going to its own mono channel. When I opened it in Audition it mixed them into one stereo channel. 
    Thanks in advance for any help.
    Best,
    Shawn 

    You're a big help! Thanks very much.  Simple yet I must be going blind because I didn't see that in the menu.
    Take care and THANKS AGAIN.
    Shawn

  • Crystal report - how to split a field into more fields

    Hello,
    I`m new to Crystal reports and I`ve got a trouble. I have field which contains an address - street, city, zip code. The example is:
    STEHLIKOVA 977 165 00 PRAHA 620 - SUCHDOL 165 00.
    What I need to achieve is to split this string into three separated fields. I`ve trouhg a couple of forums but haven`t been able to find a proper answer. The problem is that the addresses differ so I can`t use an absolute defining of a start position. Looking at the DB (HEXA code) the parts in the string are divided by two dots:
    STEHLIKOVA 977..165 00 PRAHA 620 - SUCHDOL..165 00
    I`ve been able to work out this solution:
    stringVar array x := split({cparty.STREET_ADD},"..");
    Local numberVar i;
    Local stringVar outputString := "";
    For i:=1 to Count(x) do
    outputString := outputString + x[i] + Chr(10)
    outputString;
    It splits the string into three rows:
    STEHLIKOVA 977
    165 00 PRAHA 620 - SUCHDOL
    165 00
    And I don`t know how to find the end of each row so to be able to separate the strings and report them as three different fields.
    Would be anyone so kind and help me out with this?
    Thank you.
    Petr

    Hi
    Actually using a for loop is not necessary here. All you need to do is to add several formula fields: one for street, one for city and one for zipcode. In @street field you add formula:
    stringVar array x := split({cparty.STREET_ADD},Chr(13));
    x[1];
    Then you drag such formula field to details section of your report and watch preview to check if everything looks alright. Repeat for every formula field that you'd like see in your report.
    In @city you add almost identical formula but you change index, i. e. instead of x[1] you need to use x[2]. Then for @zip x[3].
    You may need to check if your address has all three parts - for example if you want to use formula in the second part of your address field you may need check first if there are at least two parts after split:
    stringVar array := split({cparty.STREET_ADD},Chr(13));
    numbervar c; 
    c := count(x); 
    if 2 <= c then 
    x[c]; 
    Var 'c' is used to store the number of elements in array after split. Then I'd like to check if the part (second) actually exists. So I try to check if number of part that I want to refer to is not bigger than the number of elements in array after split (here stored in var 'c').
    Actually the code presented above is not enough since you have no guarantee that you'll always get address structured in the very same way. For example in demo PL database I have zip code and city in the same row after split with Chr(13) as delimiter.
    You'll need to experiment or ask someone to prepare correctly structured data coming from B1 to your report.
    Kind regards,
    Radek

  • Splitting one column into 4 columns

    Hi,
      I want to split one column into 4 columns as shown below.
    parameters
    PanelPanel=MP01110201&YearYear=2013&Source=1&UserID=aad2779
    PanelPanel=MP12100173&YearYear=2013&Source=1&UserID=aac6440
    it should be display as 
    panel                      yearyear                source              userid
    MP01110201           2013                            1                    aad2779
    MP12100173           2013                            1                    aac6440
    there will be thousands of rows in the column. Can anybody help how to split it as shown.The length may very from row to row
    Thanks for your help.........
    BALUSUSRIHARSHA

    It is working...thank u very much... I found one more issue here
    PanelPanel=MP01110201&YearYear=2013&Source=1&UserID=aad2779
    PanelPanel=MP11100070&Source=1&PNR=2&YearYear=2014&UserID=ddc1535
    PanelPanel=MP11101276&Source=1&YearYear=2014&PNR=2&UserID=ddc1565
    I found 3 kinds of formats in the same column... I didn't observe the data carefully while posting the
    question..sorry about that. In this case if we need to show as
    panel                      yearyear                source
                 userid
    MP01110201           2013                            1                    aad2779
    MP11100070           2014                           1                    ddc1535
    MP11101276           2014                
              1                    ddc1565
    is it possible to filter like this? Should we use any case statement in query while we have diff formats
    like this?
    BALUSUSRIHARSHA

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

  • Split one IDoc into two IDocs ?

    hello all,
    I wanna split one IDoc into two IDocs in XI?
    how can implement it?
    plx give some suggestions.
    thx in advance
    best regards
    Yaning
    Message was edited by:
            Yaning Liu

    Yaning,
    Please find the below blog for changing the ocurrences of IDOC
    /people/michal.krawczyk2/blog/2005/12/04/xi-idoc-bundling--the-trick-with-the-occurance-change
    Best regards,
    raj.

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

Maybe you are looking for

  • 802.11n 5ghz Connection Problem with OS X 10.4.11 Tiger

    I've searched the communities for answer to this vexing issue to no avail, so I am trying a post. Situation: I have a dual-band 1TB TC at home set up with three networks: 802.11g/b/a, 802.11n ((5ghz), and Guest Network (g/b).  There are four Macs acc

  • Can`t move image in pse 11 for correction

    I made a lot of photos during trip, all loaded on Mac. Same I need correction in Adobe Photoshop  element 11( already in computer) and several can`t loaded in Adobe 11.  When I click to open in Adobe 11 Pop up note "Could not complete your request be

  • Is using a 12 volt charger bad for my iPhone 5?

    Is using a 12 volt charger bad for my iPhone 5?  I just purchased the iPad Air and it came with the same lightning cable that was included with my iPhone 5.  The only difference is that the charger that came with my iPhone is a 10 volt and the one th

  • Printing Options

    My old MacBook (white clunky one) suddenly began to only print in black and white.  I changed printers, changed ink, ran the alignment, etc.  Nothing converted the printing back to color.  Now I have a brand new MacBook Pro and it was printing in col

  • Slide show transition in Bridge CS4 not working

    Putting together slideshows in Bridge CS4 I can not get the slide transition to work, no matter what timing I set for 'duration.' I have tried opening it in several different browsers, but no dice.  Also my slides are jpgs at 72 dpi - so, rather smal