Convert string Column into set or Rows.

Hi,
I have a difficult time converting a string column in the source table to be spitted and insert them as individual rows in target table. The source sting is separated by "-" character. And the source sting can have any number of "-" which may result in any number of out put rows.
e.g. "- IL - NY - NJ - KY - TX" "RAY" should look like
RAY IL
RAY NY
RAY NJ
RAY KY
RAY TX
in the target table.
Thanks,
Ashvin.
Edited by: user591315 on Mar 13, 2009 8:03 AM

This is working.
All you need to do in owb is pull the table function operator , config it take a ref-cursor and also give the attribute names that are declared in the type record to each of the out put variables in the table function operator.(in this case-8 variables).
Thanks,
Ashvin.
CREATE OR REPLACE
type RDW.STAFF_MEMBER_BREAKDOWN_RECORD is object
( survey_i_id number,
survey_id number,
client number,
company number,
csg number,
contact number,
pred_mode_type number,
pred_mode_string varchar2(2000));
CREATE OR REPLACE
type RDW.STAFF_MEMBER_BREAKDOWN_TABLE
is table of staff_member_breakdown_record;
CREATE OR REPLACE package RDW.refcur_pkg
as
type staff_teams_cur_type is ref cursor;
end refcur_pkg;
CREATE OR REPLACE function RDW.parse_teams
(staff_teams_cur refcur_pkg.staff_teams_cur_type)
return staff_member_breakdown_table
pipelined
is
v_survey_i_id NUMBER;
v_survey_id NUMBER;
v_client NUMBER;
v_company NUMBER;
v_csg NUMBER;
v_contact NUMBER;
v_pred_mode_type NUMBER;
v_team_members_r VARCHAR2(2000);
v_team_members VARCHAR2(2000);
cnt NUMBER;
exit_flag NUMBER;
begin
loop
fetch staff_teams_cur into v_survey_i_id,v_survey_id ,v_client,v_company,v_csg,v_contact,v_pred_mode_type,v_team_members;
exit when staff_teams_cur%notfound;
exit_flag := 0;
v_team_members_r := ltrim(v_team_members,'#') ;
loop
cnt := instr( v_team_members_r, '#' );
if ( cnt > 0 )
then
v_team_members := substr(v_team_members_r,1,instr(v_team_members_r,'#')-1);
v_team_members_r := substr(v_team_members_r,instr(v_team_members_r,'#')+1);
else
v_team_members := v_team_members_r;
exit_flag := 1;
end if;
pipe row (staff_member_breakdown_record(
to_number(v_survey_i_id),v_survey_id ,v_client,v_company,v_csg,v_contact,v_pred_mode_type, v_team_members));
exit when exit_flag = 1;
end loop;
end loop;
end parse_teams;
/

Similar Messages

  • Concatenate strings from a column into a single row

    I am trying to string values from a column into a single row. I need a list of students (one row per student) with their phone number and they could have more than one number. I found a function that should do what I need but the syntax is for SQL Server, not SQL*Plus. I've tried several variations but can not come up with the correct syntax.
    This is the SQL Server version:
    CREATE FUNCTION dbo.GetPhoneList(@StudentID int)
    RETURNS varchar(500) AS
    BEGIN
    DECLARE @StringList varchar(500)
    SELECT @StringList = COALESCE(@StringList + ‘, ‘, ”) + Telephone.PhoneNumber
    FROM Telephone t
    WHERE t.StudentID = @StudentID
    IF @StringList IS NULL
    SET @StringList = ‘No Phone’
    RETURN @StringList
    END
    SQL*Plus does not like the @ symbol, so I tried taking that out. I've put semi-colons where I think they should be, but I still get various error messages. Any suggestions?
    Thanks.

    Hi,
    What you want to do is called "String Aggregation"
    You could write a PL/SQL funcrtion to do that for a specific column in a specific table, but [this page|http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:2196162600402] has a couple of different generic solutions that will work on any tables and columns.
    I recommend the first soluton, the user-defined function STRAGG, which you can copy from that page.
    Once you have STRAGG installed, your query can be something like:
    SELECT     s.student_id
    ,     NVL ( STRAGG (t.phone_number)
             , 'No phone'
             )     AS phone_nums
    FROM          student          s
    LEFT OUTER JOIN     telephone     t     ON s.student_id     = t.student_id
    GROUP BY     s.student_id;On Oracle 10 (and up) you may have a similar function, WM_CONCAT (owned by WMSYS), already installed.
    WM_CONCAT is not documented, so you may not want to use it in your Production applications.
    It lokks like
    Edited by: Frank Kulash on Feb 10, 2009 6:31 PM

  • How to convert single column into single row

    I need to convert single column into single row having n no.of.values in a column. without using case or decode. I need a query to display as below.
    emp_id
    100
    101
    102
    102
    103
    200
    I need output like 100,101,102,103,104.........200.

    I assume you want to convert 200 rows with one column into one row with 200 columns. If so, this is called pivot. If you know number of rows (max possible number of rows) and you are on 11G you can use PIVOT operator (on lower versions GROUP BY + CASE). Otherwise, if row number isn't known, you can use dynamic SQL or assemble select on clent side. Below is example emp_id = 1,2,..5 (to give you idea) and you are on 11G:
    with emp as (
                 select  level emp_id
                   from  dual
                   connect by level <= 5
    select  *
      from  emp
      pivot(
            max(emp_id) for emp_id in (1 emp_id1,2 emp_id2,3 emp_id3,4 emp_id4,5 emp_id5)
       EMP_ID1    EMP_ID2    EMP_ID3    EMP_ID4    EMP_ID5
             1          2          3          4          5
    SQL>
    SY.

  • Converting multiple columns into one.

    All,
    I have a requirement to convert multiple columns into one. Following is the pseudo code of current implementation. It unions the various columns ( col1, col2........) into a new column new_col. But perforamnce is extrmely slow owing to multiple unions. It may be noted that tables and where conditions of all these queries are same.
    Can you help me create a more efficient query?
    select col1 , col2, col3, col4 from my_tables where some_cols = my_condition;Below is the query used to convert these columns into one.
    select col1 new_col from my_tables where some_cols = my_condition
    union all
    select col2 from my_tables where some_cols = my_condition
    union all
    select col3 from my_tables where some_cols = my_condition
    union all
    select col4 from my_tables where some_cols = my_condition

    Without looking at those things you could be barking up the wrong tree by assuming the issue relates to the unioning of queries or other such things.Well, might be.........
    Execution time of this query (just the execution time not the retrival) is around 34 seconds with connect-by clause for returning 22,000 records.
    Here's the plan
    Execution Plan
    | Id  | Operation                          | Name                        | Rows
    | Bytes | Cost (%CPU)|
    |   0 | SELECT STATEMENT                   |                             |   326
    | 33904 |   135   (2)|
    |   1 |  SORT ORDER BY                     |                             |   326
    | 33904 |   135   (2)|
    |   2 |   MAT_VIEW ACCESS BY INDEX ROWID   | MV_COMQ_RM_DEAL             |     1
    |    62 |     1   (0)|
    |   3 |    NESTED LOOPS                    |                             |   326
    | 33904 |   134   (1)|
    |   4 |     MERGE JOIN CARTESIAN           |                             |   326
    | 13692 |     3   (0)|
    |   5 |      VIEW                          |                             |     1
    |    13 |     2   (0)|
    |   6 |       COUNT                        |                             |
    |       |            |
    |   7 |        CONNECT BY WITHOUT FILTERING|                             |
    |       |            |
    |   8 |         FAST DUAL                  |                             |     1
    |       |     2   (0)|
    |   9 |      BUFFER SORT                   |                             |   326
    |  9454 |     3   (0)|
    |  10 |       TABLE ACCESS BY INDEX ROWID  | SF_SEARCH_IDS_TMP_COMQ      |   326
    |  9454 |     1   (0)|
    |  11 |        INDEX RANGE SCAN            | IDX1_SF_SEARCH_IDS_TMP_COMQ |   349
    |       |     1   (0)|
    |  12 |     INDEX RANGE SCAN               | IDX_MV_COMQ_RM_DEAL         |     9
    |       |     1   (0)|
    -----------------------     Hope, It's readable.......
    I would have posted sample data and query but........I cant do that...:(

  • Converting String Characters into Regular Expression Automatically?

    Hi guys.... is there any program or sample coding which is available to convert string characters into regular expression automatically when the program is run?
    Example:
    String Character Input: fnffffffffffnnnnnnnnnffffffnnfnnnnnnnnnfnnfnfnfffnfnfnfnfnfnnnnd
    When the program runs, it automatically convert into this :
    Regular Expression Output: f*d

    hey guys.... i am sorry for not providing all the information that you guys need as i was rushing off to urgent meeting... for my string characters i only have a to n.. all these characters are collected from sensors and stored inside database... from many demos i have done... i found out that every demo has different strings of characters collected and these string of characters will not match with the regular expressions that i had created due to several unwanted inputs and stuff... i have a lot of different types of plan activities and therefore a lot of regular expressions.... if i put [a-z|0-9]*... it will capture all characters but in the same time it will be showing 1 plan only.... therefore, i am finding ways to get the strings i collected and let it form into regular expression by themselves in the program so that it will appear as different plans as output with comparing with the regular expression that i had created.... is there any way to do so?
    please post again if there is any questions u are still not familiar with... thank you...

  • Convert single column into rows

    hi Gurus,
    I have one table test colums are id and name.
    id number
    name varchar2
    data is like
    id name
    1 xy
    2 xyy
    3 mm
    4 pp
    Now my requirement is to convert single column id into rows
    i,e my output should be of singel rows like :- 1,2,3,4
    How to achive this result .
    I dont have any idea to do this query.
    Please help guys.
    Thanks in advance.
    Vijay

    Well,
    As long as your code doesn't have to run in production, simplest way is:
    WM_CONCAT (but it's not documented)
    or use XMLAGG, it's simpler than a connect by:
    MHO%xe> with t as (
      2  select 1 col, 'xy' str from dual union all
      3  select 2, 'xyy' from dual union all
      4  select 3, 'mm'from dual union all
      5  select 4, 'pp' from dual union all
      6  select 8, 'pp' from dual union all
      7  select 12, 'pp' from dual union all
      8  select 40, 'pp' from dual
      9  )-- actual query, based on id's generated above:
    10  select rtrim(xmlagg(xmlelement(e,col||',')).extract('//text()'),',') col
    11  from   t;
    COL
    1,2,3,4,8,12,40
    1 rij is geselecteerd.

  • How to convert String array into int.

    void getSoldSms(Vector vecSoldSms)
         String str[]=new String[vecSoldSms.size()];
         String words[]=new String[str.length]; // String array
              for(int i=0;i< vecSoldSms.size();i++)
                   str=(String)vecSoldSms.get(i);
              }               //End for
              for(int i=0;i<str.length;i++)
              words = str[i].split("\\|\\|");
              System.out.println();
              for(int j=0;j<1;j++)     
              int count[str.length]=Integer.parseInt(words[i]);
              System.out.print(count[j]*advance_count);
              } // end inner for loop
              }          //End for
         }          //End function getSoldSms
    how do i convert words which is a string array into int type. i kno string can be converted into int using interger.parseint. but wat abt string arrays??? plz help me out with the above code.

    i did tht its still giving the same errorFor Heaven's sake, what about taking a second to try to understand the code you're copying first? If you really can't fix the error yourself, you have a more serious problem than just convertingStrings to ints.
    And if you want { "1", "2", "3" } to be 123:
    StringBuffer b = new StringBuffer();
    for (int i = 0; i < array.length; i++) {
      b.append(array);
    int result = Integer.parseIn(b.toString());

  • Convert 2 columns into multiple column table

    Hi,
    I have table with two columns. See below. I need to create a kind of matrix presentation of the table, so that values in row B become column titles, see second table. Amount of data is too big to create this manually.
    TC1
    Req2
    TC2
    Req1
    TC3
    Req0
    TC4
    Req1
    TC5
    Req2
    TC6
    Req3
    TC7
    Req4
    TC8
    Req5
    TC9
    Req6
    TC10
    Req7
    TC11
    Req8
    TC12
    Req9
    TC13
    Req10
    TC14
    Req11
    TC15
    Req12
    TC16
    Req7
    TC17
    Req8
    TC18
    Req3
    TC19
    Req13
    TC20
    Req14
    TC21
    Req15
    TC22
    Req16
    Req1
    Req2
    Req3
    Req4
    Req5
    Req6
    Req7
    Req8
    TC1
    X
    TC2
    X
    TC3
    X
    TC4
    X
    TC5
    TC6
    X
    X
    TC7
    X
    TC8
    TC9
    X
    X
    TC10
    TC11
    X
    TC12
    X
    TC13
    X
    X
    TC14
    X
    X
    TC15
    X
    TC16
    TC17
    X
    TC18
    X
    TC19
    TC20
    X
    X
    x
    TC21
    X
    TC22
    X
    Any suggestions how to proceed are greatly appreciated!
    Question: Would Excel's PivotTable do the trick? No scripting needed?

    Hi and thanks for your reply! I added leading zeros. I tried the formula and the result looks like this from my first sample:
    Req01
    Req02
    Req03
    Req04
    Req05
    Req06
    Req07
    Req08
    Req09
    Req10
    Req11
    Req12
    Req13
    Req14
    Req15
    Req16
    TC1
    x
    TC2
    x
    TC3
    TC4
    TC5
    TC6
    x
    TC7
    x
    TC8
    x
    TC9
    x
    TC10
    x
    TC11
    x
    TC12
    x
    TC13
    x
    TC14
    x
    TC15
    x
    TC16
    TC17
    TC18
    TC19
    x
    TC20
    x
    TC21
    x
    TC22
    x
    So row value remain empty if column value has earlier been met. Eg. TC17. Any ideas?

  • Converting columns into rows

    Dear all....I need to convert all columns into rows in a table. For example table has following columns:
    Emp_Cod........Val1......Val2......Val3
    1 a b c
    Now I wish that each column should display as a value like:
    Emp_Cod........Val1
    1 a
    1 b
    1 c
    Now the one way to solve this job is to write a union statement for each column but for this I'll have to write equal number of select statements as there are columns.
    What I need that is there anyway to write minimum code for this job, is there any alternate way???

    SQL> with t as(select 1 emp_code, 'a' val1, 'b' val2, 'c' val3 from dual)
      2  select*from t unpivot(v for c in(val1,val2,val3));
    EMP_CODE  C     V                                                      
            1  VAL1  a                                                      
            1  VAL2  b                                                      
            1  VAL3  c                                                      
    SQL> col COLUMN_VALUE for a20
    SQL> with t as(select 1 emp_code, 'a' val1, 'b' val2, 'c' val3 from dual)
      2  select*from t,table(sys.odcivarchar2list(val1,val2,val3));
    EMP_CODE  V  V  V  COLUMN_VALUE                                        
            1  a  b  c  a                                                   
            1  a  b  c  b                                                   
            1  a  b  c  c                                                   

  • How to convert blob data into clob using plsql

    hi all,
    I have requirement to convert blob column into clob .
    version details
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production
    PL/SQL Release 11.1.0.7.0 - Production
    CORE     11.1.0.7.0     Production
    TNS for 32-bit Windows: Version 11.1.0.7.0 - Production
    NLSRTL Version 11.1.0.7.0 - Production
    DECLARE
       v_blob      temp.blob_column%TYPE;------this is blob data type column contains  (CSV file which is  inserted  from screens)
       v_clob      CLOB; --i want to copy blob column data into this clob
       v_warning   NUMBER;
    BEGIN
       SELECT blob_column
         INTO v_blob
         FROM temp
        WHERE pk = 75000676;
       DBMS_LOB.converttoclob (dest_lob          => v_clob,
                               src_blob          => v_blob,
                               amount            => DBMS_LOB.lobmaxsize,
                               dest_offset       => 1,
                               src_offset        => 1,
                               blob_csid         => 1, -- what  is the use of this parameter
                               lang_context      => 1,
                               warning           => v_warning
       DBMS_OUTPUT.put_line (v_warning);
    EXCEPTION
       WHEN OTHERS
       THEN
          DBMS_OUTPUT.put_line (SQLCODE);
          DBMS_OUTPUT.put_line (SQLERRM);
    END;I am not getting what is the use of blob_csid , lang_context parameters after going the trough the documentation .
    Any help in this regard would be highly appreciated .......
    Thanks
    Edited by: prakash on Feb 5, 2012 11:41 PM

    Post the 4 digit Oracle version.
    Did you read the Doc for DBMS_LOB.CONVERTTOCLOB? - http://docs.oracle.com/cd/B28359_01/appdev.111/b28419/d_lob.htm
    The function can convert data from one character set to another. If the source data uses a different character set than the target you need to provide the character set id of the source data.
    The blob_csid parameter is where you would provide the value for the source character set.
    If the source and target use the same character set then just pass zero. Your code is passing a one.
    >
    General Notes
    You must specify the character set of the source data in the blob_csid parameter. You can pass a zero value for blob_csid. When you do so, the database assumes that the BLOB contains character data in the same character set as the destination CLOB.
    >
    Same for 'lang_context' - your code is using 1; just use 0. It is an IN OUT
    >
    lang_context
    (IN) Language context, such as shift status, for the current conversion.
    (OUT) The language context at the time when the current conversion is done.
    This information is returned so you can use it for subsequent conversions without losing or misinterpreting any source data. For the very first conversion, or if do not care, use the default value of zero.

  • Writing BLOB column into a csv or txt or sql  files

    Hi All,
    I am having a requirement where i have to upload a file from user desktop and place that file into a unix directory. For this i am picking that file into a table using APEX and then writing that file in unix directory using UTL_FILE.
    The problem which i am facing is that after this every line in my file is having ^M character at the end.
    For this i modified my BLOB column into a CLOB column and then also i am facing the same problem.
    Is there any way to get rid of this as i have to upload these csv or txt files into tables using sql loader programs. i can;t write any shell script to remove ^M character before uploading as this program will be merge with existing programs and then it will require lots of code change.
    Kindly Help.
    Thanks
    Aryan

    Hi Helios,
    Thanks again buddy for your reply and providing me different ways.... but still the situation is i can;t write any shell script for removing the ^M. I will be writing into a file from CLOB column.
    Actually the scenrio is when i am writing a simple VARCHAR columns with 'W' mode then it is working fine, but i have a BLOB column which stores the data in binary format so i am converting that column into CLOB and then writing it into file with 'W' mode but then i am getting ^M characters. As per your suggestion i have to then again run a program for removing ^M or i have to modify all my previous programs for removing ^M logic.
    I want to avoid all these, and just wanted a way so that while writing into a file itself it should not have ^M. Else i have to go for a java stored procedure for running a shell script from sql, and in this still i am having some problem.
    Thanks Again Helios for your time and help.
    Regards
    Aryan

  • Need to Convert Comma separated data in a column into individual rows from

    Hi,
    I need to Convert Comma separated data in a column into individual rows from a table.
    Eg: JOB1 SMITH,ALLEN,WARD,JONES
    OUTPUT required ;-
    JOB1 SMITH
    JOB1 ALLEN
    JOB1 WARD
    JOB1 JONES
    Got a solution using Oracle provided regexp_substr function, which comes handy for this scenario.
    But I need to use a database independent solution
    Thanks in advance for your valuable inputs.
    George

    Go for ETL solution. There are couple of ways to implement.
    If helps mark

  • To convert columns into row

    Hi All,
    I need help in building view which actually can show columns data as row.
    e.g.
    row is as follows
    Name Age Salary
    ABC 25 10000
    BBC 28 12000
    The above tables data I want to get as
    Name ABC BBC
    Age 25 28
    Salary 10000 12000
    Thanks in advance.

    Even if I don't really understand such requirement, I wrote some times ago such function to play around that :
    Re: Converting Columns into rows
    Nicolas.

  • Converting multiple column rows into single column

    Hi all Below is my requirement, can you anybody help me solve it. CREATE TABLE TYPE (   c1_type  VARCHAR2 (10),   c2_type  VARCHAR2 (10),   c3_type  VARCHAR2 (10),   c4_type  VARCHAR2 (10),   c5_type  VARCHAR2 (10),   c6_type  VARCHAR2 (10),   c7_type  VARCHAR2 (10),   c8_type  VARCHAR2 (10),   c9_type  VARCHAR2 (10)); INSERT INTO TYPE     VALUES ('Region_D',             'Region_E',             'Region_F',             'Region_D',             'Region_E',             'Region_D',             'Region_M',             'Region_D',             'Region_E'); commit; Acutal output on the below query select * from type; C1_TYPE C2_TYPE C3_TYPE C4_TYPE C5_TYPE C6_TYPE C7_TYPE C8_TYPE C9_TYPE Region_D Region_E Region_F Region_D Region_E Region_D Region_M Region_D Region_E Acutal i am expecting the below output,how to make it using query or using oracle built in function. Region_D Region_D Region_D Region_D Region_E Region_E Region_E Region_F Region_M

    Hi,
    So, you want to put the column values in alphabetic order, with the earliest value in c1_type and the last in c9_type, is that it?
    The fact that you even want to do this says that this is a bad table design.  If sorting the values makes sense, then putting them all in the same column on 9 different rows (rather than 9 different columns on 1 row) makes sense.
    If you're stuck with the current design, then use SELECT ... UNPIVOT to put them on separate rows, then use the analytic ROW_NUMBER function to assign numbers 1-9 to each value, and finally use SELECT ... PIVOT to put them back into 1 row in that order.  If you're not familiar with the built-in UNPIVOT and PIVOT features, look them up in the SQL Language manual, and see the forum FAQ:
    https://forums.oracle.com/message/9362005
    If you get stuck, post your best attempt (formatted), the exact results you want (formatted), and your Oracle version (e.g. 11.2.0.2.0).
    Also, TYPE is an Oracle keyword, so it's not a good table name.  Use something like location_type instead.

  • Stop download to Excel from converting string of digits & dashes into date

    Hi,
    How can I stop BI and Excel data from converting a column of string data that is comprised of numbers and dashes into a date format when it is downloaded into Excel?
    I'd like to solve this problem in BI, so that any users can download the data from a BI report into Excel without having to change the Excel date column back into a string column.
    Thanks,
    Darcy

    Hi Again Darcy,
    hmmm... That is very interesting. I just tried on OBIEE 10.1.3.2 ( a version before yours) on Windows XP with Office 2003 and an Oracle 11g DB backend and it did not have any problems pulling the value as text and not a DATE
    Can you try something for me? In a new report, add any old dimensional (year, month name, etc) field twice into the report and change the second column formula to be following: '7001-2'
    Try to export that report and see if that value comes through as text or a date. If it is something about the SQL server data set, then the above test should come through as text object in your excel download because we aren't pulling it from SQL Server, we'll creating it directly in OBIEE. If the above test does come through as a date, then it should mean that SQL Server isn't the issue. And if that is the case, I am starting to wonder if there's a setting in Office to can be enabled/disabled to avoid any data casting.
    Best regards,
    -Joe

Maybe you are looking for

  • Remote Access VPN Support in Multiple Context Mode (9.1(2))?

    Hi Guys, I am currently running two Cisco ASA5520 (ASA Version: 9.1(2)) firewalls in Active/Standby failover and was contemplating the option of migrating my remote access VPN to these firewalls. However seeing that the new IOS now support mixed mult

  • Report template issue.

    Hi All, I'm using ApEx 4.1.0.00.32 I have a report and I want to add a title to a field. I thought it would be as easy as adding title="#my_title_column#" into the element attributes section in the column attributes region for the item. Nothing appea

  • How create graphs(pie and bar graphs) in j2me

    hi friends, how to create graphs in j2me? plz help me. regards, Shruthi R S

  • Unit missing or error returned when Project Explorer open

    Hi, I found out strange behaviour when I open VI from Project Explorer, and I don't know why is this happening. It can be tested with files in attached archive. When I open UnitMissingTest.vi directly from directory (Project Explorer is not opened) a

  • Apple TV 2 G - Can only see a few songs in my library, can't see any Movies

    Just bought the Apple TV. I thought that once I setup Homesharing that I would be able to see my entire iTunes library including music and movies. Thus far I can only see a few songs. I have updated my iTunes to 10.2 and checked for software updates