Need help in converting rows to colums

Hi all,
I have a table with 2 columns.
colId value
1 aaa
2 bbb
3 ccc
1 ddd
2 eee
3 fff
I want to store the above table's data into another table which has 3 columns.
col1 col2 col3
aaa bbb ccc
ddd eee fff
I'm trying pivot query. But i'm not getting it correctly. Please help.
I have Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
Thanks in advance,
Girish G
Edited by: Girish G on Jul 28, 2011 1:28 AM

Girish G wrote:
Hi Tubby,
Let me explain the actual scenario.
I'm getting CLOB data from external source to oracle stored procedure.
The data is coming in the following form.
col1#|#col2#|#col3~|~col1#|#col2#|#col3~|~col1#|#col2#|#col3
Here #|# -> is column delimiter.
and ~|~ -> is row delimiter.
I want to store the above data into a table which has 3 columns.
My approach was to extract each column data and store it in temporary table in separate rows. Then move the data from temporary table to final destination table.
Is there any other alternative for my requirement? please suggest.
Thanks,
Girish GMuch better when you show us the context like this.
It's late and i have sleepiness within my bones so this isn't likely optimal.
select
   regexp_substr(split, '[^@]+', 1, 1) as col1 ,
   regexp_substr(split, '[^@]+', 1, 2) as col2 ,
   regexp_substr(split, '[^@]+', 1, 3) as col3
from
   select
      replace(regexp_substr(source_str, '[^@]+', 1, level), '#|#', '@') as split
   from
      select
         replace('val1#|#val2#|#val3~|~val4#|#val5#|#val6~|~val7#|#val8#|#val9', '~|~', '@') as source_str
      from dual
   connect by level <= length(source_str) - length (replace(source_str, '@') )  + 1
);I also don't have an 11 instance running (tested this on XE) so i can't use 'magical' things like regexp_count and fun stuff. This should give you a basic idea of how to parse the data though.
I decode your delimiters into something "more manageable" just because it's easier than worrying about escaping special characters and all that fun stuff i'm too sleepy to try.
Since you're dealing with a CLOB (do you actually have more than 4000 characters of data?) you may have to abandon this and look in to a pipelined function as a suitable alternative.

Similar Messages

  • I need help in converting a pdf to a fillable form in my adobe

    I need help in converting a pdf to a fillable form in my adobe

    "Adobe" is a company. If you mean "Adobe Reader" then you can't (at least not easily). You need Adobe Acrobat for that.

  • Need help in converting numbers to Italian text

    Need help in converting numbers to text in Italian language. I want to knw is there any method other than SE63 to translate these text in one shot. I have tried with LSMW also (as the sheet is in XLS format ).Plz reply if anyone is aware of this ..

    hi,
    chk this code.
    CALL FUNCTION 'SPELL_AMOUNT'
    EXPORTING
    amount = amount
    currency = 'EUR'
    filler = ' '
    language = 'E'  => give the language as italian
    IMPORTING
    in_words = amountrs.
    rgds
    anver
    pls mark all hlpful answers

  • Need help in converting date format

    Hi,
    Need help in converting date format from 'DD-MON-YYYY' to 'YYYY-MM-DD' in an .rtf template as I believe xml publisher supports the date format as 'YYYY-MM-DD' only.
    Thanks,
    Raj.

    I got the same problem, anyone know how to solve this problem? I allready found some date functions on http://blogs.oracle.com/xmlpublisher/2008/09/date_functions.html . I also tried <?xdoxslt:month_name(xdoxslt:get_month(xdofx:substr(NEED_BY_DATE, 4,3)), $_XDOLOCALE), 0, 'nl-NL')?>, but then it returns a namespace error (Caused by: oracle.xdo.parser.v2.XPathException: Namespace prefix 'xdofx' used but not declared.). Anyone know how to fix this?
    Edited by: user11165753 on 7-dec-2009 23:50

  • Need help with Pivoting rows to columns

    Hi,
    I need help with pivoting rows to columns. I know there are other posts regarding this, but my requirement is more complex and harder. So, please give me a solution for this.
    There are two tables say Table 1 and Table 2.
    Table1
    name address email identifier
    x e g 1
    f s d 2
    h e n 3
    k l b 4
    Table2
    identifier TRno zno bzid
    1 T11 z11 b11
    1 T12 z12 b12
    1 T13 z13 b13
    2 T21 z21 b21
    2 T22 z22 b22
    As you can see the identifier is the column that we use to map the two tables. The output should be like below
    output
    name address email identifier TRno1 zno1 bzid1 TRno2 zno2 bzid2 TRno3 zno3 bzid3
    x e g 1 T11 z11 b11 T12 z12 b12 T13 z13 b13
    f s d 2 T21 z21 b21 t22 z22 b22
    Also we do not know exactly how many TRno's, zno's, etc each value in the identifier will have. There may be only 1 TRNO, zno and bzid, or there may be four.
    All the values must be in separate columns, and not be just comma delimitted. There are also other conditions that i have to add to restrict the data.
    So, can you please tell me what is should use to get the data in the required format? We are using Oracle 10g. Please let me know if u need any more information

    Something like this ?
    SCOTT@orcl> ed
    Wrote file afiedt.buf
      1  select a.name,
      2  a.address,
      3  a.email,
      4  b.* from (
      5  select distinct identifier
      6  ,max(trno1) trno1
      7  ,max(zno1) zno1
      8  ,max(bzid1) bzid1
      9  ,max(trno2) trno2
    10  ,max(zno2) zno2
    11  ,max(bzid2) bzid2
    12  ,max(trno3) trno3
    13  ,max(zno3) zno3
    14  ,max(bzid3) bzid3
    15  ,max(trno4) trno4
    16  ,max(zno4) zno4
    17  ,max(bzid4) bzid4
    18  from (select identifier
    19  ,decode(rn,1,trno,null) trno1
    20  ,decode(rn,1,zno,null) zno1
    21  ,decode(rn,1,bzid,null) bzid1
    22  ,decode(rn,2,trno,null) trno2
    23  ,decode(rn,2,zno,null) zno2
    24  ,decode(rn,2,bzid,null) bzid2
    25  ,decode(rn,3,trno,null) trno3
    26  ,decode(rn,3,zno,null) zno3
    27  ,decode(rn,3,bzid,null) bzid3
    28  ,decode(rn,4,trno,null) trno4
    29  ,decode(rn,4,zno,null) zno4
    30  ,decode(rn,4,bzid,null) bzid4
    31  from (select identifier,
    32  trno,bzid,zno,
    33  dense_rank() over(partition by identifier order by trno,rownum) rn
    34  from table2)
    35  order by identifier)
    36  group by identifier) b,table1 a
    37* where a.identifier=b.identifier
    SCOTT@orcl> /
    NAME       ADDRESS    EMAIL      IDENTIFIER TRNO1      ZNO1       BZID1      TRNO2      ZNO2       BZID2      TRNO3      ZNO3       BZID3      TRNO4      ZNO4       BZID4
    x          e          g          1          T11        z11        b11        T12        z12        b12        T13        z13        b13
    f          s          d          2          T21        z21        b21        T22        z22        b22
    SCOTT@orcl> select * from table1;
    NAME       ADDRESS    EMAIL      IDENTIFIER
    x          e          g          1
    f          s          d          2
    h          e          n          3
    k          l          b          4
    SCOTT@orcl> select * from table2;
    IDENTIFIER TRNO       ZNO        BZID
    1          T11        z11        b11
    1          T12        z12        b12
    1          T13        z13        b13
    2          T21        z21        b21
    2          T22        z22        b22
    SCOTT@orcl>Regards
    Girish Sharma

  • Need help to convert SQL MSSQL statement to work with PL in ORACLE

    Hi All,
    I have the trigger below and it worked on MSSQL server for windown and
    I really need your help to convert this trigger to work on PL/ORACLE:
    create trigger deleteLD
         on tablea for delete
    as
    set nocount on
    begin
         declare @tablename varchar(100)
         declare @dropSql varchar(50)
         select @tablename= dataset from deleted
         set @tablename = 'LD_' + @tablename
         set @tablename = @tablename + 'UTMSTATS'
         if exists (select * from sysobjects where name = @tablename)
         begin
              set @tablename = 'drop table ' + @tablename
              EXEC (@tablename)
         end
    end
    GO
    Your help is greatly appreciated.
    Thanks,
    JP

    not sure if this is something that you want:
    Create Or Replace Trigger deleteLD
      Before Delete on tablea
    Declare
      vCtr          number := 0;
    Begin
    select count(*)
       into vCtr
       from all_tables
      where table_name = :new.tablename;
    if vCtr > 0 then
       dbms_utility.exec_ddl_statement('drop table '||:new.table_name);
    end if;
    End;note: not tested

  • I need help to convert hours,minutes and seconds to seconds.

    Hi, I need help with the code on how to convert the hours,minutes and seconds to seconds. I don't know which formula to use so that I can get the results in total number of seconds. Thanks.

    Jos ("when in doubt: parenthesize correctly")Bracist.You're more right than you'd known: last week I climbed over a safety
    fence (which I wasn't supposed to do of course) to adjust the position
    of an optical measurement device we installed in a huge production
    machine in a factory. I stepped on some sort of hose; the end of that
    hose broke loose and hit me straight in the middle of my lower jaw. My
    front teeth feel wiggly now and my molars on the left of my lower jaw are
    not what they used to be. This Wednesday I get that all fixed at some
    dental clinic. Keep your fingers crossed because me+dentists == war.
    My tongue continuously keeps on reporting craters and disaster ;-)
    Jos, how's it going? Besides a possible loss of some teeth, I'm fine ;-)
    My Spring/Hibernate journey continues. I'm trying out Hibernate 3.2
    annotations and the Ant tools. So far, so good.Good to hear. At the moment I'm putting my teeth (sic) in that darn snmp
    stuff which simply refuses to work the way I want it and besides that I'm
    heavily involved in some of that SAP stuff. Spring is not in the vicinity for
    me in the next couple of months sadly enough.
    kind regards,
    Jos

  • I need help to convert photos in the .swf format to a format that will open on iOS

    I need help converting photos in the .swf format to a format that will work on my Mac.  Thanks

    SWF is a Flash file that should be able to be opened with your web browser on your Mac. Probably not on iOS though.
    You will likely need to find the source file for the application that created the SWF and the image will be in that. You could then export/extract the image and have it as a stand alone file.
    It does look like there are applications that can do what you are looking for though: https://www.google.com/search?q=SWF+to+JPG

  • Need help regarding updated rows

    Dear sir,
    need help on this query
    how many rows got updated when i execute an update statement

    If you are executing update statement from sqlplus session.
    Make sure "feedback" is turned on. It'll show numbers of rows updated just after the command;
    SQL> update tt1 set col1 = 1;
    0 rows updated.
    SQL> show feedback
    FEEDBACK ON for 1 or more rows
    SQL> set feedback off
    SQL> update tt1 set col1 = 1;
    SQL>Details about this sqlplus system setting:
    FEED[BACK] {6|n|OFF|ON}
    Display the number of records returned (when rows >= n )
    OFF (or n=0) will turn the display off
    ON will set n=1
    Regards,
    Ullhas

  • I need help to convert a string to date and time

    Good aft,
    1.How can i get a date from the user input thro' Frames?
    2.How to parse it to the date object(I need to include java.util.Date but for the database i need to include java.sql.*,if i do so, i have error as
    found:java.util.Date
    Required:java.sql.Date)
    3.How to insert into the database
    The same i need help to insert time into database?
    I need solution and explanation...
    Reply me immediately...
    If u send me the code, its better to me.

    Hello,
    The best way is to use the HEX to decimal coversion VI in the string pallette. Then, write this decimal directly to your chart. If you are doing it a point at a time put it into a while loop.
    Doug

  • Need help in converting DAQ to DAQmx

    Hi,
    I've struggled with coverting traditional DAQ to DAQmx for two weeks. I really need help from someone.
    As you can see the picture below, I've tried to replace the old VI's with new ones. But, it doesn't work. Of course, the VI below is just a part of my VI. VI's after case structure are inside of while loop.
    Could you please give me thought that why it doesn't work?
    FYI: The strange thing about it is that it runs without any error messege, but there is no actual output (values on the graph, data in arrays, etc).  
    Thanks in advance.
    Best,
    Jay
    Solved!
    Go to Solution.
    Attachments:
    Untitled 1.vi ‏74 KB

    Hi Jay,
    Assuming that the Traditional DAQ and DAQmx code are screenshots from separate VIs, I believe that the following parameter of the read functions in each driver would account for the different behavior that you are seeing (you have both set to -1):
    Traditional DAQ:
     DAQmx:
    So, when you give DAQmx Read a -1 for "number of samples per channel" when running a Continuous task, the effect is that it will return whatever data is available at the time DAQmx Read is called.  In your case this is immediately after the task is started so there very well could be 0 samples available in the buffer.  I'd imagine that you would see data if you change the value of this parameter from -1 to the actual number of samples that you want to read.
    Having said this, if you want to acquire continuously you should call DAQmx Read from inside a loop.  I agree with the others that you should take a look at the DAQmx shipping examples to help get started, you will probably find something very close to what you want to do.  You can find the examples at:
    Help >> Find Examples... >> Hardware Input and Output >> DAQmx
    Thanks for posting, I hope this helps!
    -John
    John Passiak

  • Loader (Need help to convert from AS3 to AS2)

    Since I know this code works fine and that I use it into one of my AS3 flash, I need it in one of my AS2 flash and I don't know how to adapt it. I've searched in over 100 threads and I can't find something similar... Thanks to help me get it to work in AS2! Since I need it in AS2, I thought it would be the right place to post it.
    I posted all the loading process code, but I would need help mostly with the Loader part. How to do it in AS2? Thanks!
    var img = 0;
    var image_total = 0;
    var myImages_array:Array = new Array();
    var myBitmaps_array:Array = new Array();
    function Init();
    // Images urls are loaded into an array before this call
    LoadImage();
    function LoadImage()
        if (img < myImages_array.length) // img is the current image index and myImages_array is my array of URLs
    // I need help with this part please
            var loader:Loader = new Loader();
    // returns the image full path and load it
            loader.load(new URLRequest(my_site_url + myImages_array[img]));
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
        else
            if (count == 0)
    // When everything's loaded, I'll start loading my Bitmaps into a small slideshow
                count += 1;
                init_slideshow();
    function imageLoaded(e:Event):void
        var image:Bitmap = e.target.content;
    // Bitmap manipulation here (removed)
        image_total = myBitmaps_array.push(image);
        if (img < myImages_array.length)
            img += 1;
    // Call next image
            LoadImage();
    function init_slideshow():void
    // Reserts the current index for the first one
        img = 0;
    // Start the slideshow since everything's loaded
        animate_slideshow();

    If you look at the Flash help documentation for the addListener metod of the MovieClipLoader class, there is an erxample there that you should hopefully be able to work from.  It will be better if you get your stuff coded into AS2 before you pursue more help with it.  IT is difficult to tell you how to fix something if you don't show what you are using.

  • Need help in displaying Rows to Columns

    Hi,
    I am facing problem in displaying Rows to Columns
    I am using pivot function:
    select *
    from
    (select vendor_name
    from tablea)
    pivot
    (count(vendor_name)
    for vendor_name in ('a,b,'c'));
    its working fine showing vendor_name and count
    but when i want to display the output as:(How to include the Salalry column in the query?)
    Name:{a b c}
    Sal Total:(400,600,800}
    Any help will be needful for me

    Not sure what you mean:
    select  *
      from  (select deptno,sal from emp)
      pivot(sum(sal) for deptno in (10,20,30))
            10         20         30
          8750      10875       9400
    SQL> SY.

  • Need help for converting c# encryption code to javascript

    I have this below code in c# i need to convert it into nodejs i would really appriciate some help in this.
    Rfc2898DeriveBytes passwordDb2 = new Rfc2898DeriveBytes(passphrase, Encoding.ASCII.GetBytes(DeriveSalt(grains)));
    byte[] nonce = passwordDb2.GetBytes(NonceSize);
    AesManaged symmetricKey = new AesManaged { Mode = CipherMode.ECB, Padding = PaddingMode.None };
    _encryptor = symmetricKey.CreateEncryptor(_nonces[0], null);
    public byte[] Encrypt(byte[] plainText, int blockIndex)
    byte[] nonceEncrypted = new byte[NonceSize];
    byte[] outputData = new byte[_chunkSize];
    _encryptor.TransformBlock(_nonces[blockIndex], 0, NonceSize, nonceEncrypted, 0);
    for (int i = 0; i < _chunkSize; i++)
    outputData[i] = (byte)(plainText[i] ^ nonceEncrypted[i % NonceSize]);
    return outputData;
    public byte[] Decrypt(byte[] encryptedText, int blockIndex)
    byte[] nonceEncrypted = new byte[NonceSize];
    byte[] outputData = new byte[_chunkSize];
    _encryptor.TransformBlock(_nonces[blockIndex], 0, NonceSize, nonceEncrypted, 0);
    int index = 0;
    for (int i = 0; i < _chunkSize; i++, index++)
    if (index == NonceSize)
    index = 0;
    outputData[i] = (byte)(encryptedText[i] ^ nonceEncrypted[index]);
    return outputData;
    Currently i have the below code from what i understood (I am quite new to nodejs)
    var crypto = require("crypto");
    var nonce = crypto.pbkdf2Sync(passphrase, "grains", 1000, NonceSize);
    _encryptor = crypto.createCipheriv('aes-128-ecb', binkey, "");
    _decryptor = crypto.createDecipheriv('aes-128-ecb', binkey, "");
    Encrypt: function (plainText, blockIndex) {
    var nonceEncrypted = [NonceSize];
    var outputData = [_chunkSize];
    var crypted = Buffer.concat([_encryptor.update(plainText), _encryptor.final()]);
    for (var i = 0; i < _chunkSize; i++) {
    outputData[i] =(plainText[i] ^ nonceEncrypted[i % NonceSize]);
    var x = new Buffer(outputData);
    return x;
    Decrypt: function (encryptedText, blockIndex) {
    var nonceEncrypted = [NonceSize];
    var outputData = [_chunkSize];
    var decrypt = Buffer.concat([_decryptor.update(encryptedText), _decryptor.final()]);
    var index = 0;
    for (var i = 0; i < _chunkSize; i++, index++) {
    if (index == NonceSize)
    index = 0;
    outputData[i] = (encryptedText[i] ^ nonceEncrypted[index]);
    var x = new Buffer(outputData);
    return x;

    Maybe, you should post to the Javascript secition of the ASP.NET forum.
    http://forums.asp.net/

  • Need Help opening converted file in Pages

    I have a Mac and use Pages as my word processor.  Pages converts Word documents into its format so that they can be opened, read and edited.  I have never been unable to open/use a document opened this way . . . till now. The downloaded document won't open in Pages.  It says it is an "invalid format."  I hope someone can help me.  The purchase of the Adobe program is no value to me if I can't use it, and I need to be able to use documents in this way.  Thanks in advance.

    You can set up a link to behave as you want, ignoring whatever the user preference is set to, but I don't know if you can configure such a link in InDesign.
    In Acrobat, you can edit the link action (assuming it's a "Go to a page view / Go to a page in another document" type) and select "New Window" in the "Open in" drop down:

Maybe you are looking for