Pivoting string values( ,comma seperator) to separate columns(usingREG_EXP)

<pre>
I have column PART which contains string as shown below
PART
BMW PART,TEST PART,TEST PART,HYPER PART,HYPER PART,TESTINGNEWONE,TESTINGNEWONE,TESTINGNEWONE
string has got comma separated, i need to project as individual columns like
P1 P2 .... P8
BMW PART TEST PART TESTINGEWONE
how can it be done... (i think by using regular expressions it can be done but i am not aware of it can any one help)
</pre>
Thanks
Naren

Hi,
Narendar.Vishwanatham wrote:
thanks a lot for your query....
cant we make it dynamically instead of hardcoding each columnThe number of columns produced by a query must be hard-coded into the query.
Dynamic SQL means that you have some program (often another query) write all or part of the main query for you.
The following thread has an example of a dynamic pivot in SQL*Plus:
Help for a query to add columns
The following thread discusses different options for dealing with an unknown number of columns after the pivot:
Re: Report count and sum from many rows into many columns
(and i guess the answer you gave is not possible to get with out using regular expresssions right !!!)No, you can get the same results using INSTR and SUBSTR.
Whenever you ask for help, post a little sample data (CREATE TABLE and INSERT statements), and the results you want from that data.
Always mention what version of Oracle (and any other relevant tools) you're using. This is especially important with pivots; recent versions of Oracle have helpful new features.

Similar Messages

  • How to convert string containing comma seperated values to an array

    my requirement is i have to first convert an comma seperated string to an array
    after that i have to pass the array values to a for loop
    eg:i have a string str=(456,457,487,465,478)
    These values i have to put in an array.
    i then i have to pass the array values to a for loop

    We understand your ¿homeworks? We are helping you, but it seems like you want us to do it.
    Try it yourself with some of the instructions.
    Anyway if there aren´t homeworks, use dinamyc sql:
    declare
    varray := '(45,65,12,4)';
    begin
    execute immediate 'update table set ss=''uu'' where id in ' || varray;
    end;

  • Values in Colum as separate columns

    I have a table that looks like this:
    Company (varchar),
    FieldName (varchar)
    Valuex (varchar)
    Data may look like this:
    Company Fieldname Valuex
    123 Name John
    123 MiddleName C
    123 LastName Smith
    I would like to write a query that comes out like this:
    Company FirstName MiddleName LastName
    123 John C Smith
    Can it be one? Thanks in advance.

    Hi,
    Pivot is new in 11g is it not? I'm on 10g. Can it be done without the pivot function?Yes! You can do pivots in any version. I just said there was a newer, easier way that was introduced in Oracle 11; that's the only case in which the word PIVOT occurs in the code.
    I just tried searching for "pivot", and I did find dozens of examples. Almost all of them said "Search for pivot", so I'll post an exmple here. The example below works in any version of Oracle, including 10.
    --     How to Pivot a Result Set (Display Rows as Columns)
    --     This example uses the scott.emp table.
    --     Given a query that produces three rows for every department,
    --     how can we show the same data in a query that has one row
    --     per department, and three separate columns?
    --     For example, the query below counts the number of employess
    --     in each departent that have one of three given jobs:
    PROMPT     ==========  0. Simple COUNT ... GROUP BY  ==========
    SELECT     deptno
    ,     job
    ,     COUNT (*)     AS cnt
    FROM     scott.emp
    WHERE     job     IN ('ANALYST', 'CLERK', 'MANAGER')
    GROUP BY     deptno
    ,          job;
    Output:
        DEPTNO JOB              CNT
            20 CLERK              2
            20 MANAGER            1
            30 CLERK              1
            30 MANAGER            1
            10 CLERK              1
            10 MANAGER            1
            20 ANALYST            2
    PROMPT     ==========  1. Pivot  ==========
    SELECT     deptno
    ,     COUNT (CASE WHEN job = 'ANALYST' THEN 1 END)     AS analyst_cnt
    ,     COUNT (CASE WHEN job = 'CLERK'   THEN 1 END)     AS clerk_cnt
    ,     COUNT (CASE WHEN job = 'MANAGER' THEN 1 END)     AS manager_cnt
    FROM     scott.emp
    WHERE     job     IN ('ANALYST', 'CLERK', 'MANAGER')
    GROUP BY     deptno;
    --     Output:
        DEPTNO ANALYST_CNT  CLERK_CNT MANAGER_CNT
            30           0          1           1
            20           2          2           1
            10           0          1           1
    --     Explanation
    (1) Decide what you want the output to look like.
         (E.g. "I want a row for each department,
         and columns for deptno, analyst_cnt, clerk_cnt and manager_cnt)
    (2) Get a result set where every row identifies which row
         and which column of the output will be affected.
         In the example above, deptno identifies the row, and
         job identifies the column.
         Both deptno and job happened to be in the original table.
         That is not always the case; sometimes you have to
         compute new columns based on the original data.
    (3) Use aggregate functions and CASE (or DECODE) to produce
         the pivoted columns. 
         The CASE statement will pick
         only the rows of raw data that belong in the column.
         If each cell in the output corresponds to (at most)
         one row of input, then you can use MIN or MAX as the
         aggregate function.
         If many rows of input can be reflected in a single cell
         of output, then use SUM, COUNT, AVG, STRAGG, or some other
         aggregate function.
         GROUP BY the column that identifies rows.
    {code}
    Edited by: Frank Kulash on Sep 5, 2008 5:37 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to show string value with spaces in seperate columns

    Hi all, I'm using Oracle 10g.
    create table
    create table sample_test (
      Name    VARCHAR2(20 BYTE))insert table
    insert into sample_test values ('JOAN   SCT')
         insert into sample_test values ('MELIA FILCK')
          insert into sample_test values ('SSAN LIER-LILEY')
           insert into sample_test values ('C.M. DANY WES')
               insert into sample_test values ('A L SCOTT')select * from sample_test;
    Name
    JOAN   SCT
    MELIA FILCK
    SSAN LIER-LILEY
    C.M. DANY WES
    A L SCOTTi would like the output as follows
    NAME1        NAME2      NAME3
    JOAN          SCT              
    MELIA        FILCK              
    SSAN       LIER-LILEY
    C.M.          DANY       WES
    A             L          SCOTTwhen ever there is a space in the name the value next to that should be shown in an other column. please note the first name joan sct has two spaces. but it needs to be treated as single space.
    also is it possible to get something like this
    NAME1        NAME2    
    JOAN          SCT              
    MELIA        FILCK              
    SSAN       LIER-LILEY
    C.M.DANY       WES
    A L          SCOTTthe value before first space on the right should be in name2 everything else in name1 field.
    Thanks in advance.

    Hi,
    Since you have Oracle 10, you can use regular expressions:
    For the 3-column output:
    SELECT        REGEXP_SUBSTR (name, '[^ ]+', 1, 1)     AS name1
    ,        REGEXP_SUBSTR (name, '[^ ]+', 1, 2)     AS name2
    ,        REGEXP_SUBSTR (name, '[^ ]+', 1, 3)     AS name3
    FROM        sample_test;     [^xyz]     means "any character except x, y or z".
    +     means "1 or more of the preceding"
    The 4th argument to REGEXP_SUBSTR tells which occurrence of the pattern we want.
    For the 2-column output:
    SELECT        REGEXP_REPLACE (name, ' *[^ ]+$')     AS before_last_space
    ,        REGEXP_SUBSTR  (name,   '[^ ]+$')     AS after_last_space
    FROM        sample_test;$     here means "the end of the string".
    In Oracle 10, you often have to use REGEXP_REPLACE to get substrings.
    Thanks for posting the CREATE TABLE and INSERT statements; that's very helpful!
    Edited by: Frank Kulash on Sep 7, 2011 3:21 PM

  • Count the number of elements in comma seperated list of values

    Hello Friends,
    I have a string with comma seperated list of values say
    String v = 34343,erere,ererere,sdfsdfsdfs,4454,5454,dsfsdfsfsd,fsdfsdfsdfs,dfdsfsdfsdfs,sdsfdsf,ererdsdsd45454,fsdfsdfs
    Want to count how many elements are existing in this string .
    Thanks/Kumar

    Hi, Kumar,
    REGEXP_COUNT, which Hoek used, is handy, but it only works in Oracle 11. Which version of Oracle are you using?
    In any version of Oracle, you can count the commas by seeing how much the string shrinks when you remove them.
    LENGTH (str) + 1 - LENGTH (REPLACE (str, ',')) Can str have multiple commas in a row? What if there's nothing between consecutive commas, or nothing by whitespace? Can str begin or end with a comma? Can str consist of nothing but commas? Depending on your answers, you may have to change things. You might want
    REGEXP_COUNT ( str
                 , '[^,]+'
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using.
    See the forum FAQ {message:id=9360002}

  • How to extract member, default alias and custom alias into separate columns

    Hi,
    is there a way to get simultaneously member name, default alias name and custom alias name with Essbase 9x report scripts (Report Writer)?
    I do know that using for example
    <OUTALTSELECT "default or custom alias table"
    <REPMBRALIAS "dimension"
    I can get both the real member name and selected alias table, but the problem is that they're both returned to same column.
    Using fix columns and order I can repeat member name into several columns if needed, but I would need to tell what to put for each column.
    For example : { ORDER 0,0,0,1,2,3,4,5 FIXCOLUMNS 8 }
    I would like to force the report script to put Member name into first column in row, default alias name of member into second column in row and custom alias name of member into third column in row, like :
    MEMBERNAME DEFAULTALIASNAME CUSTOMALIASNAME
    Any ideas how to handle this?
    I can of course create several extracts containing one sort of info per list, but it would make life somewhat easier having all of these in same extract.
    Thanks in advance!
    Br,
    MK

    Hi,
    well, that's pretty much what I want to achieve, to get all info of member within same row, but into separate columns.
    The other option is to then produce 2 other extracts containing:
    Extract 1:
    MEMBERNAME DEFAULTALIASNAME
    and
    Extract 2:
    MEMBERNAME CUSTOMALIASNAME
    These values should be in separate columns?
    I think I lost the track while playing around with report writer, does anyone have a ready made solution for this?
    <REPMBRALIAS brings the needed info, but returns the values into same column.
    Empty space delimiter could be handled with customalias table, but in this case default alias name may have long text with several empty spaces making it hard to sort in the other system side.
    Any suggestions?
    Thanks so far for your kind help.
    Br,
    MK

  • Have a column which is having comma seperated values.. and i am trying to s

    Have a column which is having comma seperated values.. and i am trying to seperate it.
    I am trying to create a stored procedure ..Version 11g xe. .and apex version 4..
    Here is the part of code..I cant make a procedure. .cause my statement consist with clause..
    create or replace procedure ins_adv_invoice
    (mmagazine_no number,madvtno number,missueno number,msection varchar2,mpagenumber varchar2,msalesman_code varchar2)
    is
    cursor cx is with testa as
    (select pagenumber name from advertiser)
    select regexp_substr(pagenumber, '[^,]+', 1, rownum) result
    from advertiser
    connect by level <= length(regexp_replace(pagenumber, '[^,]+')) + 1
    where advt_no = madvtno;
    begin
    for xxx in cx
    loop
    insert into adv_invoice (magazine_no,advtno,adissue,section,page_number,salesman_code)
    values (mmagazine_no,madvtno,missueno,msection,xxx.result,msalesman_code);
    end loop;
    end;
    But when i run this .. it doesnt create procedure. .I get he following error..
    LINE/COL ERROR
    5/14 PL/SQL: SQL Statement ignored
    9/69 PL/SQL: ORA-00933: SQL command not properly ended
    SQL>
    Still not able to figure it out..Can any one help..
    Thanks

    Change the query to swap the last two lines:
    cursor cx is with testa as
    (select pagenumber name from advertiser)
    select regexp_substr(pagenumber, '[^,]+', 1, rownum) result
    from advertiser
    where advt_no = madvtno
    connect by level <= length(regexp_replace(pagenumber, '[^,]+')) + 1;
    ...

  • Column should display comma seperated value.

    Hi All,
    Iam working on Reports6i.
    In my data model i have a query which gives some product names(only one column), i need to display those product names with a comma seperator.
    Just like Product1,Product2,....
    Can anybody guide me as this is very urgent.
    Thanks in Advance
    Chinni.

    something like this ?
    WITH DATA AS (SELECT 'X' product,1 order_id FROM DUAL
                  UNION ALL
                  SELECT 'Y' product,1 order_id FROM DUAL
                  UNION ALL
                  SELECT 'Z' product,1 order_id FROM DUAL
                  UNION ALL
                  SELECT 'XX' product,2 order_id FROM DUAL
                  UNION ALL
                  SELECT 'YY' product,2 order_id FROM DUAL
                  UNION ALL
                  SELECT 'ZZ' product,2 order_id FROM DUAL
    SELECT LTRIM(sys_connect_by_path(product,','), ',') PRODUCTS
      FROM (SELECT product,
                   order_id,
                   row_number()   OVER (partition by order_id order by product) RN,
                   count(product) OVER (partition by order_id) MAXROW
              FROM data) 
    WHERE RN=MAXROW CONNECT BY     PRIOR RN+1=RN
                                AND PRIOR ORDER_ID=ORDER_ID START WITH RN=1

  • Mapping a column with comma seperated values

    Hi,
    I have two tables
    1. Tasks (task_id, task_description)
    2. Task_assignment (username, task_assignment_value)
    the task_assignment_value has a comma seperated list of task_ids.
    What is the best ways to map the tables ?
    Thanks in advance.
    Moinuddin Mohammed

    I have a couple of attributes where I do this. From TopLink's perspective, I just map it as a String. Then, in my accessors for the attribute, I transform the primitive between the String and an Array or however the rest of the app wants to see the attribute.
    Here's an example that's actually more complicated than absolutely necessary. The mapped attributed is indicatorValueListString. It is lazily converted to an Array of Enums when it is first accessed. And it is converted back to a String in the preWriteEventCallback that is mapped in the TopLink descriptor.
    This implementation attempts to minimize the number of times the String<->Array conversion takes place, but if that's not a concern, it could be made much more simple. Also, at my company we privately manage collections with the Collection classes for dynamic allocation, but publicly exchange Arrays for type-safety. This could also be factored out. ValuedEnumUtils basically manages asking the enum for its delimiter and performing the actual conversion between a String and an Array or back.
    private String indicatorValueListString;
    private List indicatorValueSelections;
    private List indicatorValueSelections() {
            if (indicatorValueSelections == null) {
                    indicatorValueSelections = new ArrayList();
                    if (indicatorValueListString != null) {
                            indicatorValueSelections =
                                    java.util.Arrays.asList(ValuedEnumUtils.decodeEnumString(
                                         IndicatorValueEnum.class,indicatorValueListString));
            return indicatorValueSelections;
    private void indicatorValueSelections(List newIndicatorValueSelections) {
            indicatorValueSelections = newIndicatorValueSelections;
    public IndicatorValueEnum[] getIndicatorValueSelections() {
            return (IndicatorValueEnum[])indicatorValueSelections().toArray(new IndicatorValueEnum[0]);
    public void setIndicatorValueSelections(IndicatorValueEnum[] newIvSelections) {
            indicatorValueSelections(java.util.Arrays.asList(newIvSelections));
    public boolean addIndicatorValueSelection(IndicatorValueEnum anIvEnum) {
            return indicatorValueSelections().add(anIvEnum);
    public boolean removeIndicatorValueSelection(IndicatorValueEnum anIvEnum) {
            return indicatorValueSelections().remove(anIvEnum);
    public void preWriteEventCallback(DescriptorEvent aDescriptorEvent) {
            // Note: Not using accessor to avoid lazy initialization if no changes
            // are necessary.
            if (indicatorValueSelections != null) {
                    indicatorValueListString =
                            ValuedEnumUtils.encodeEnumString((ValuedEnum[])indicatorValueSelections.toArray());
    }

  • Inserting comma seperated values

    I created a stored procedure that creates an order_id. Using this id, the products and their pricetag are inserted. Hereafter the garnishes are inserted for each product.
    Creating an order id and inserting the products and their pricetag are working. The problem is at the inserting of garnishes. 
    The data is received by parameters, and I have also created a user defined type: where garnishId holds the comma seperated ids.
    CREATE TYPE [dbo].[ppg] AS TABLE(
    [ProductId] [int] NULL,
    [PriceId] [int] NULL,
    [garnishId] [VARCHAR](MAX) NULL
    this is the stored procedure:
    ALTER PROCEDURE [dbo].[sp_create_order]
    (@userId uniqueidentifier, @productPriceGarnishes dbo.ppg READONLY, @comment varchar(250))
    AS
    BEGIN
    DECLARE @orderId int
    DECLARE @orderDetailId int
    INSERT INTO orders (user_id, confirmed,comment) values(@userId,0,@comment);
    --Select last inserted PK
    SELECT @orderId=SCOPE_IDENTITY()
    -- insert products and price tag using @orderId
    INSERT INTO order_detail (order_id, product_id,price_id)
    SELECT @orderId, p.ProductId,
    p.PriceId
    FROM @productPriceGarnishes p
    SELECT @orderDetailId=SCOPE_IDENTITY()
    -- insert garnishes using the orderDetailId
    INSERT INTO order_detail_garnish (order_detail_id,garnish_id)
    SELECT @orderDetailId, (SELECT * FROM SplitDelimiterString(p.garnishId))
    FROM @productPriceGarnishes p
    END
    RETURN @orderId
    I found a function that splits the string by a delimiter in this website:
    http://www.codeproject.com/Tips/586395/Split-comma-separated-IDs-to-ge
    Where you can retrieve the ids by this query:
    (SELECT * FROM SplitDelimiterString(p.garnishId)
    The problem is that I don't know how to add these ids with their corresponding orderDetailId, after each product is added.

    Unfortunately it appears you assume too much.  Presumably the reason you chose to define @productPriceGarnishes as a table is to support the creation of multiple rows. And you use these rows to insert into the order_detail table which has an identity
    column as the primary key (again, presumably).  So the question then becomes how do you get the identity values for ALL of the inserted rows?  You can't do that with SCOPE_IDENTITY - your code currently is designed with the assumption that there
    is only one row to be inserted.  To work around that limitation you need to use the output clause (examples can be found by searching). 
    Next comes another problem.  How do you know which identity value is assigned to which row of your table variable during the insert?  You need some sort of natural key to associate the inserted rows with the rows in the table variable.  Do
    you have one?  Before you think you do, you need to think about what restrictions are placed on the content of the table variable (if any).  Is it possible to have multiple rows with the same values for ProductId and PriceId?  Do not assume
    - you need to be certain that this is or is not a possibility.
    Assuming that the rows are unique (which simplifies things greatly), you associate the inserted order_detail rows to the table variable via something like:
    select ... from @ins_detail as ins inner join @productPriceGarnishes as ppg
    on ins.ProductId = ppg.ProductId and ins.PriceId = ppg.PriceId
    Note that @ins_detail is a table variable that you would declare and populate via the output clause. It will contain the identity values for each row that you inserted.  With that, you can then generate the rows that you need to insert into the garnish
    table by applying the results of your splitter function.  Which is a step that I'll skip for now since you have much reading and work to do. 
    Now some last comments.  I am suspicious of a column named PriceId.  That is not a good sign - price is an attribute of something and not the basis of a relationship between tables.  The use of identity columns (especially as primary keys)
    can be a problem - and this is one good example.  Based on what I've just written and its assumptions, the natural key for order_detail is (order_id, product_id, price_id) - why do you need an identity column?  Again, searching will find past
    discussions about identity columns and their usage.

  • 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

  • Operations on comma seperated values..

    Hi all,
    We have some histogramic values which are kept in one column and from time to time we need to propagate them in order to fill the history tables like :
    table_1
    c1 -- c2 -- c3
    a -- 1,1,1--11
    a -- 2,2,2--11
    a -- 3,3,3--11
    b -- 4,4,4--22
    b -- 5,5,5-22
    c -- 6,6,6-22
    select c1,sum???(c2),sum(c3) from table_1 group by c1;
    c1 -- sum???(c2) -- sum(c3)
    a -- 6,6,6--33
    b -- 15,15,15--66
    The point is to do the operations seperaterly with the first value, second value,... seperately.
    Any ideas about this ?
    Thanks,
    Evren

    Hi, Evren,
    Welcome to the forum!
    Whenever you have a problem, it helps if you post your sample data in some form that people can use to actually re-create it.
    CREATE TABLE and INSERT statements are great. for example:
    CREATE TABLE     table_1
    (      c1     VARCHAR2 (5)
    ,      c2     VARCHAR2 (20)
    ,      c3     NUMBER
    INSERT INTO table_1 (c1, c2, c3) VALUES ('a', '1,1,1', 11);
    INSERT INTO table_1 (c1, c2, c3) VALUES ('a', '2,2,2', 11);
    INSERT INTO table_1 (c1, c2, c3) VALUES ('a', '3,3,3', 11);
    INSERT INTO table_1 (c1, c2, c3) VALUES ('b', '4,4,4', 22);
    INSERT INTO table_1 (c1, c2, c3) VALUES ('b', '5,5,5', 22);
    INSERT INTO table_1 (c1, c2, c3) VALUES ('c', '6,6,6', 22);That's not a very good design. If the items in c2 are separate entities, they should be in separate columns (or maybe on sepaarte rows, in a separate table, with a one-to-many relationship to table_1).
    If you can't change the table structure permanently (which is the best solution), then you'll have to generate a result set that mimics that (more or less) every time you need to use that column as separate entities.
    [This thread|http://forums.oracle.com/forums/thread.jspa?threadID=945432&tstart=0] shows how to split a delimited list into parts.
    After you've calculated the individual totals, use the || operator to cram them back into one column, if necessary.
    For example:
    SELECT       c1
    ,       SUM (TO_NUMBER (REGEXP_SUBSTR (c2, '[^,]+', 1, 1))) || ',' ||
           SUM (TO_NUMBER (REGEXP_SUBSTR (c2, '[^,]+', 1, 2))) || ',' ||
           SUM (TO_NUMBER (REGEXP_SUBSTR (c2, '[^,]+', 1, 3)))          AS sum_c2
    ,       SUM (c3)                                                     AS sum_c3
    FROM       table_1
    GROUP BY  c1
    [email protected] wrote:Hi all,
    We have some histogramic values which are kept in one column and from time to time we need to propagate them in order to fill the history tables like :
    table_1
    c1 -- c2 -- c3
    a -- 1,1,1--11
    a -- 2,2,2--11
    a -- 3,3,3--11
    b -- 4,4,4--22
    b -- 5,5,5-22
    c -- 6,6,6-22
    select c1,sum???(c2),sum(c3) from table_1 group by c1;
    c1 -- sum???(c2) -- sum(c3)
    a -- 6,6,6--33
    b -- 15,15,15--66Are you sure that's the output you want from the data you gave?
    When I run the query above with the same data, I get:
    C1    SUM_C2                   SUM_C3
    a     6,6,6                        33
    b     9,9,9                        44
    c     6,6,6                        22

  • I want to create stored procedure which will give output rows from "values that are passed as one parameter (comma seperated) to store procedure".

    Hello,
    I want to create stored procedure which will give output rows from "values that are passed as one parameter (comma seperated) to store procedure".
    Suppose , 
    Parameter value : person 1,person2,person3 
    table structure : 
    Project Name | officers 1 | officers 2
    here, officers 1 or officers 2 may contain names of multiple people.
    expected OUTPUT : distinct list(rows) of projects where person 1 or person 2 or person 3 is either officer1 or officer 2. 
    please explain or provide solution in detail 
    - Thanks

    Hi Visakh,
    Thanks for reply.
    But the solution you provided giving me right output only if officer 1 or officer 2 contains single value , not with comma seperated value.
    Your solution is working fine for following scenario : 
    Project 
    Officers 1
    Officers 2
    p1
    of11
    off21
    p2
    of12
    off22
    with parameter : of11,off22 : it will give expected output
    And its not working in case of :
    Project 
    Officers 1
    Officers 2
    p1
    of11,of12
    off21,off23
    p2
    of12,of13
    off22,off24
    with parameter : of11,off22 : it will not give any row in output
    I need patten matching not exact match :) 
    ok
    if thats the case use this modified logic
    CREATE PROC GetProjectDetails
    @PersonList varchar(5000)
    AS
    SELECT p.*
    FROM ProjectTable p
    INNER JOIN dbo.ParseValues(@PersonList,',')f
    ON ',' + p.[officers 1] + ',' LIKE '%,' + f.val + ',%'
    OR ',' + p.[officers 2] + ',' LIKE '%,' + f.val + ',%'
    GO
    Keep in mind that what you've done is a wrong design approach
    You should not be storing multiples values like this as comma separated list in a single column. Learn about normalization . This is in violation of 1st Normal Form
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Regarding get the space seperated string values

    Hi ,
    I have product description column having value:'NEW,CAPSULE,200MG,1MLX10 0126-10 (DD) (RX)'.I'm able to get the comma sperated values but stuck with space seperated values could you please some one help me how to get the space seperated values.I appreciate your help in this regard.Below is the query which returns comma seperated value as NEW .
    select substr( x||',', 1, instr(x,',')-1 ) name from table
    Thanks,
    Ravi

    we can do that.. But I would suggest first convert them into as single separator
    as as you already saying you got comma separatedlist.. first convert all into comma separted.
    replace spaces with comma.
    replace(str,' ', ',')
    SELECT     LEVEL AS n,
                         REGEXP_SUBSTR (replace('NEW,CAPSULE,200MG,1MLX10 0126-10 (DD) (RX)',' ',','),
                                        '[^,]+',
                                        1,
                                        LEVEL
                                       ) AS val
                    FROM dual
              CONNECT BY REGEXP_SUBSTR (replace('NEW,CAPSULE,200MG,1MLX10 0126-10 (DD) (RX)',' ',','),
                                        '[^,]+',
                                        1,
                                        LEVEL
                                       ) IS NOT NULL

  • How to get the values in separate columns

    Hello Everyone
    I am new to Bex, i have the sales data of 2008,2009,2010. now i have to display the sales order(key figure) for 2008,2009,2010 in separate columns for each customer(dimension) in a single report , can any one help me how to get this done in bex.
    Thanks
    Gupta

    Hi ,
    You can achieve this either creating New Selections or Restricted Key Figures.
    Right click on the structute>>>> New selcection>>> drag the year to right [  Right Click on it >>restrict it with 2008}>>>Drag the respected Key figure.
    So u will get the values 2008 in seperate column.
    COpy the New Selecten that u created and paste on the structure , chage the descriprion and year to 2009.
    do the same for 2010.
    Note:you can also achieve this by creating variable offsets.Check the following link
    http://help.sap.com/saphelp_bw33/helpdata/en/3f/89533e5ff4d064e10000000a114084/content.htm
    Regards,
    Ranganath

Maybe you are looking for