Comma delimeted string in IN clause of PL/SQL block

Hi,
I am using string having comma separted string in IN clause of PL/SQL block.
But it does not give me right result.
If i m using sql query then give me result.
I m using oracl 10g and following code. DEPT table having 'miller' and 'cleark' ename rows.
Can you please suggest the other way to get proper result.
declare
cnt number:=0;
strin varchar2(40);
begin
strin:='miller,cleark';
select count(*)
into cnt
from dept
where ename in (strin);
dbms_output.put_line('cnt:-'||cnt);
end;Thanks.

Apart from the solutions you've already been given, let's be clear...
user548963 wrote:
I am using string having comma separted string in IN clause of PL/SQL block.
But it does not give me right result.Yes it does, it's giving exactly the expected result for what you have provided. It may not be what you're desiring, but it's absolutely correct.
The IN Clause is expecting multiple arguments to be in the set of data. You are providing it with a single argument... a single string. Just because your string has got commas in it does not make that string into multiple arguments.

Similar Messages

  • Splitting of comma delimited string CONNECT BY Clause

    Hi ,
    I have got a problem in splitting a comma separated strings into rows .
    I am explaining the use case below :
    i have a table x_imp
    --> create table x_imp (id number, int_status varchar2(100),c_ref varchar2(30), s_ref varchar2(30));
    I inserted values into the table :
    insert into x_imp (id, int_status,c_ref,s_ref) values (1,'a1,a2,a3,a4','A','AS');
    insert into x_imp (id, int_status,c_ref,s_ref) values (1,'b1,b2,b3,b4','B', 'BS');
    insert into x_imp (id, int_status,c_ref,s_ref) values (1,'c1,c2,c3,c4', 'C', null);
    insert into x_imp (id, int_status, cust_ref, site_ref) values (1,NULL, 'D', NULL);
    I need to split the comma separated int_status into individual rows . That means my expected result is :
    . What I need or looking for as expected result:
    1, A, AS, a1
    1, A, AS, a2
    1, A, AS, a3
    1, A, AS, a4
    1, B, BS, b1
    1, B, BS, b2
    1, B, BS, b3
    1, B, BS, b4
    1, C, null, c1
    1, C, null, c2
    1, C, null, c3
    1, C, null, c4
    I currently have a solution using Regex . But this solution uses UNIQUE keyword .
    The solution i have currently :
    select UNIQUE c_ref,s_ref, regexp_substr(int_status,'[^,]+', 1, level) error_code
    from x_imp
    connect by regexp_substr(int_status, '[^,]+', 1, level) is not null;
    I need a better solution . Any pointers ?
    Thanks,
    Bibin

    One way of doing using MODEL clause:
    select c_ref, s_ref, res err_code
      FROM x_imp
    model
    partition by ( id, c_ref, s_ref)
    dimension by ( 1 rn)
    measures( int_status, cast(null as varchar2(100)) res,
              nvl(length(regexp_replace(int_status, '[^,]')),0)+1 nb )
    (res[for rn from 1 to nb[1] increment 1]=regexp_substr(int_status[1], '[^,]+', 1, cv(rn)))
    order by c_ref, s_ref;
    C_REF                          S_REF                          ERR_CODE                                                                                            
    A                              AS                             a3                                                                                                  
    A                              AS                             a4                                                                                                  
    A                              AS                             a1                                                                                                  
    A                              AS                             a2                                                                                                  
    B                              BS                             b2                                                                                                  
    B                              BS                             b1                                                                                                  
    B                              BS                             b3                                                                                                  
    B                              BS                             b4                                                                                                  
    C                                                             c4                                                                                                  
    C                                                             c3                                                                                                  
    C                                                             c1                                                                                                  
    C                                                             c2                                                                                                  
    D                                                                                                                                                                 
    13 rows selected

  • MODEL clause to process a comma separated string

    Hi,
    I'm trying to parse a comma separated string using SQL so that it will return the parsed values as rows;
    eg. 'ABC,DEF GHI,JKL' would return 3 rows;
    'ABC'
    'DEF GHI'
    'JKL'
    I'm thinking that I could possibily use the MODEL clause combined with REGULAR expressions to solve this as I've already got a bit of SQL which does the opposite ie. turning the rows into 1 comma separated string;
    select id, substr( concat_string, 2 ) as string
    from (select 1 id, 'ABC' string from dual union all select 1, 'DEF GHI' from dual union all select 1, 'JKL' from dual)
    model
    return updated rows
    partition by ( id )
    dimension by ( row_number() over (partition by id order by string) as position )
    measures ( cast(string as varchar2(4000) ) as concat_string )
    rules
    upsert
    iterate( 1000 )
    until ( presentv(concat_string[iteration_number+2],1,0) = 0 )
    ( concat_string[0] = concat_string[0] || ',' || concat_string[iteration_number+1] )
    order by id;
    Can anyone give me some pointers how to parse the comma separated string using regexp and create as many rows as needed using the MODEL clause?

    Yes, you could do it without using ITERATE, but FOR ... INCREMENT is pretty much same loop. Couple of improvements:
    a) there is no need for CHAINE measure
    b) there is no need for CASE in RULES clause
    c) NVL can be applies on measures level
    with t as (select 1 id, 'ABC,DEF GHI,JKL,DEF GHI,JKL,DEF GHI,JKL,DEF,GHI,JKL' string from dual
       union all
        select 2,'MNO' string from dual
        union all
       select 3,null string from dual
    SELECT  id,
             string
      FROM   T
       MODEL
        RETURN UPDATED ROWS
        partition by (id)
        DIMENSION BY (0 POSITION)
        MEASURES(
                 string,
                 NVL(LENGTH(REGEXP_REPLACE(string,'[^,]+','')),0)+1 NB_MOT
        RULES
         string[FOR POSITION FROM  1 TO NB_MOT[0] INCREMENT 1] = REGEXP_SUBSTR(string[0],'[^,]+',1,CV(POSITION))
    SQL> with t as (select 1 id, 'ABC,DEF GHI,JKL,DEF GHI,JKL,DEF GHI,JKL,DEF,GHI,JKL' string from dual
      2     union all
      3      select 2,'MNO' string from dual
      4      union all
      5     select 3,null string from dual
      6      )
      7   SELECT  id,
      8           string
      9    FROM   T
    10     MODEL
    11      RETURN UPDATED ROWS
    12      partition by (id)
    13      DIMENSION BY (0 POSITION)
    14      MEASURES(
    15               string,
    16               NVL(LENGTH(REGEXP_REPLACE(string,'[^,]+','')),0)+1 NB_MOT
    17              )
    18      RULES
    19      (
    20       string[FOR POSITION FROM  1 TO NB_MOT[0] INCREMENT 1] = REGEXP_SUBSTR(string[0],'[^,]+',1,CV(POSITION))
    21      )
    22  /
            ID STRING
             1 ABC
             1 DEF GHI
             1 JKL
             1 DEF GHI
             1 JKL
             1 DEF GHI
             1 JKL
             1 DEF
             1 GHI
             1 JKL
             2 MNO
            ID STRING
             3
    12 rows selected.
    SQL> SY.

  • Split Comma Delimited String Oracle

    I want to Split Comma Delimited string in oracle9i into rowwise data.i do not want to use Functions or connect by level...
    is there any other way from which we can split strings.???
    if we use Connect by level method the problem im facing is we cannot use suqueries in Connect by clause...
    Edited by: user11908943 on Sep 16, 2009 8:37 AM

    michaels2 wrote:
    I prefer using XMLTABLE which has superceded XMLSEQUENCE and I personally find it easier to read...Agree, but that would be hard in 9i since it is not implemented ;)Ah! missed that bit (gawd I wish people would upgrade to supported versions)
    In still later versions (11g) I prefer
    SQL>  with t as
    select 'a,b,c,d,e' str from dual
    select trim(column_value) str
    from t, xmltable(('"' || replace(str, ',', '","') || '"'))
    STR                                                                            
    a                                                                              
    b                                                                              
    c                                                                              
    d                                                                              
    e                                                                              
    5 rows selected.
    Natty! But completely illogical (I mean creating an XMLTABLE from a non-XML string). I'm guessing that's a development of XQuery?

  • Look Up For Comma Separated Strings

    Hi,
    How to look up for comma separated string from livecycle forms manager ??
    Plz gimme an idea on this.
    Raghava Kumar V.S.S.

    Hi
    My point is that the more detailed you ask your question, the more likely you are to get an answer.
    Those of us who monitor these newsgroups also appreciate you doing as much of your own research as possible, before asking us for help - we're more likely to spend our own (personal and valuable) time helping you, if we know that you've spent your own time doing research, and you've still not been able to solve the problem.
    I look forward to your next question :-)
    Howard

  • How to remove the comma from string

    Hi,
    I Have string like below :
    String some1="123,44.22";
    I want to remove comma from string and final output should be 12244.22.
    public class getOut{
    public static void main(String args[]){
    String some1="123,44.22";
    getChars(int 0,some1.length(),char[] dst,0);
    can somebody in the forum give me idea how to remove comma from the String and
    have a string without comma.
    Thanks
    Jack

    int idx = oldString.indexOf(',');
    if(idx >= 0)   
          newString = oldString.substring(0, idx) + oldString.substring(idx + 1);or for jdk 1.4 and later
    str = str.replaceAll(",", "");

  • Using a comma-delimited string in Dynamic SQL

    Hi --
    If I receive a comma-delimited string as an in parameter, can I simply use that (in string format) when building my dynamic sql?
    Thanks,
    Christine

    The problem is, that you can not use bind variables
    here, only literals. This causes
    eventual performance problems.And to avoid the inevitable database performance problems Dmytro mentions you can use a function to convert the string to a varray and select from that. This also avoids having to use dynamic sql.
    First you create a varray and conversion function.
    SQL> create or replace type tabstr_t as table of varchar2(255)
      2  /
    Type created.
    SQL> create or replace function tabstr (
      2      p_str in varchar2,
      3      p_sep in varchar2 default ','
      4      )
      5  return tabstr_t
      6  as
      7      l_str long default p_str || p_sep;
      8      l_tabstr tabstr_t := tabstr_t();
      9  begin
    10      while l_str is not null loop
    11          l_tabstr.extend(1);
    12          l_tabstr(l_tabstr.count) := rtrim(substr(
    13                  l_str,1,instr(l_str,p_sep)),p_sep);
    14          l_str := substr(l_str,instr(l_str,p_sep)+1);
    15      end loop;
    16      return l_tabstr;
    17  end;
    18  /
    Function created.Then you can use these in either regular sql.
    SQL> var s varchar2(100)
    SQL> exec :s := 'Smith,Scott,Miller'
    PL/SQL procedure successfully completed.
    SQL>
    SQL> select * from emp where ename in
      2      (select upper(column_value) from table(tabstr(:s)));
    EMPNO ENAME    JOB          MGR HIREDATE     SAL   COMM  DEPTNO
      7369 SMITH    CLERK       7902 17-DEC-80    800             20
      7788 SCOTT    ANALYST     7566 09-DEC-82   3000             20
      7934 MILLER   CLERK       7782 23-JAN-82   1300             10Or in pl/sql.
    SQL> var c refcursor
    SQL> begin
      2      open :c for
      3      select * from emp where ename in
      4          (select upper(column_value) from table(tabstr(:s)));
      5  end;
      6  /
    PL/SQL procedure successfully completed.
    SQL> print c
    EMPNO ENAME    JOB          MGR HIREDATE     SAL   COMM  DEPTNO
      7369 SMITH    CLERK       7902 17-DEC-80    800             20
      7788 SCOTT    ANALYST     7566 09-DEC-82   3000             20
      7934 MILLER   CLERK       7782 23-JAN-82   1300             10

  • Passing comma separated string to stored procedure

    Hi,
    There is thread with same query I created earlier and that was answered. That solution worked if I pass comma separated string containing IDs. But due to changes in the logic, I have to pass usernames instead of userIDs. I tried to modify the solution provided to use with this.
    Following the link to previous post :
    Re: Passing comma separated string to stored procedure
    ------Package-------
    TYPE refcurQID IS REF CURSOR;
    TYPE refcurPubs IS REF CURSOR;
    procedure GetAllPersonalQueue (p_user_name in nvarchar2, TestQID OUT Test.refcurQID
    , TestPubs OUT Test.refcurPubs);
    ------Package-------
    ------Package Body-------
    PROCEDURE GetAllPersonalQueue (p_user_name in nvarchar2, TestQID OUT Test.refcurQID, TestPubs OUT Test.refcurPubs) as
    BEGIN
    Open TestQID for
    select id from cfq where name in (p_user_name);
    Open TestPubs for
    SELECT qid FROM queues WHERE qid in(
    select id from cfq where name in (p_user_name));
    END GetAllPersonalQueue;
    ------Package Body-------
    Thanks in advance
    Aditya

    Hi,
    I modified the query as per the solution provided by isotope, after which the logic changed and I am passing username instead of userID in comma separated string.
    Following is the changes SP, which does not throw any error, but no data is returned.
    PROCEDURE GetAllPersonalQueue (p_user_name in nvarchar2, TestQID OUT Test.refcurQID, TestPubs OUT Test.refcurPubs
    ) is
    --local variable
    strFilter varchar2(100);
    BEGIN
    Open TestQID for
    select id, name from cfq where name in
    select regexp_substr(p_user_name||',','[a-z]+[0-9]+',1,level)
    from dual
    connect by level <= (select max(length(p_user_name)-length(replace(p_user_name,',')))+1
    from dual)
    Open TestPubs for
    SELECT qid FROM queues WHERE qid in(
    select id from cfq where name in
    select regexp_substr(p_user_name||',','[a-z]+[0-9]+',1,level)
    from dual
    connect by level <= (select max(length(p_user_name)-length(replace(p_user_name,',')))+1
    from dual)
    END GetAllPersonalQueue;
    Edited by: adityapawar on Feb 27, 2009 8:38 AM

  • Comma delimited string relating to subreports

    I previously opened a discussion called comma delimited string for a report header. The response I received then worked well for 'Year' but not for two other areas I am trying to use it for.
    Original Code
    Details:
    whileprintingrecords;
    stringvar Year:= Year+ {@Year} + ", ";
    Report Footer:
    whileprintingrecords;
    stringvar Year;
    Left(Year, len(Year)-2);
    I needed to modify the code to eliminate duplication in Year and this worked fine. See the code below. I also needed this code for two other areas, Author and School. Without the extra line of code with the 'instr' function the code would always show and error for ' Left(author, len(author)-2);'.  It came up with and error saying that the result was less than 0 or not and integer and went into debug mode. I added the instr function line and it worked for most but not all. This is my problem. Either the ' Left(author, len(author)-2);' line or 'If instr(author, {@Author } ) = 0 then' makes data disappear. It will show a comma delimited string for 'Author' on most rows but not from some. The same would be true for' School'. I am not sure what is going on. The code below is what I am currently using in the subreports.
    Details:
    whileprintingrecords;
    stringvar author;
    If instr(author, {@Author}) = 0 then
        author:= author + {@Author } + ", ";
    Report Footer:
    whileprintingrecords;
    stringvar author;
    If instr(author, {@Author } ) = 0 then
        author:= author + {@Author }  + ", ";
    Else
        Left(author, len(author)-2);

    Hi Abhilash,
    The code for the @Author is:
    If ({Command.chrStatus} = "External")then
        {Command.chrSurname} & ", " & {Command.chrFirstname}
    Else
        {Command.chrSurname(1)} & ", " & {Command.chrFirstname(1)}
    The goal of this code was to pull all the authors into one comma delimited string.
    eg Smith, Brian; Jones, Barry; Lee, Henry
    The same desire was with the Schools and the code was the same. I just don't know why this is returning the blanks.
    You mentioned in the last post that this would be better done in an SQL command. Should I open up another discussion because I think this would be the way to go. I just don't know how I can do the same comma delimited code in SQL.
    Thanks

  • Converting Floats to comma-delimited strings?

    Does anyone know of any methods or classes that can convert a float to a comma delimited string?
    Alternatively, conversion of a non-comma delimited string to a comma-delimited string would be just as good.
    An example of a comma-delimited string would be the display on the iPhone calculator.
    -- tia rick

    Also in this guide:
    https://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/DataFo rmatting/DataFormatting.html
    and a small example:
    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
    //[numberFormatter setFormat:@"$#,##0;$#,##0;-$#,##0"];
    label.text = [numberFormatter stringFromNumber:[NSNumber numberWithFloat:floatVal]];
    [numberFormatter release];
    notice the commented out line is commented out because apparently setFormat is not supported on the iPhone (yet???) It's what I really need.
    good luck

  • DRM Function to divide comma delimited string to list value

    Hi
    Any one knows how to seperate comma delimited string into list values.
    Thanks

    Are you wanting to dynamically set the list values for a property? If so there are a couple options:
    1. You can update them via the API.
    2. You can write a sql script to update the table Property_List. This requires an application server restart and generally isn't recommended for support reasons but it makes sense in some instances.
    Edited by: Naren Truelove on 16/02/2011 22:08

  • Using a comma seprated string as rows

    i hv a column in which i store comma seprated name, i have to show them as rows in a report..
    plz help

    As with most things, it depends greatly on your Oracle version (you should always post this information).
    In release 11 here's a neat method.
    http://laurentschneider.com/wordpress/2009/07/select-from-column-separated-list.html
    In release 10 there's REGEXP
    http://nuijten.blogspot.com/2009/07/splitting-comma-delimited-string-regexp.html
    And it looks like you've been given a pre-10 answer already.

  • [svn:osmf:] 15983: Updating VideoQoSPluginMetadataSynthesizer to create comma separated string values for all of the available keys .

    Revision: 15983
    Revision: 15983
    Author:   [email protected]
    Date:     2010-05-10 04:47:46 -0700 (Mon, 10 May 2010)
    Log Message:
    Updating VideoQoSPluginMetadataSynthesizer to create comma separated string values for all of the available keys.
    Modified Paths:
        osmf/trunk/apps/samples/plugins/VideoQoSPlugin/src/org/osmf/qos/VideoQoSPluginMetadataSyn thesizer.as

    Rob:
    "but the sad thing is, that managers will most likely respond with a "This used to be fast in MSSQL, but now it isn't any more in Oracle. Oracle is so slow ...""
    On the bright side, it sounds like most of the database calls are implemented as stored procedures, so there is an opportunity to do it right (in Oracle terms) in the stored procedures.
    I did a similar conversion a while back, converting bad SQLServer procedures to good Oracle procedures. Everyone said "Oracle is much faster that SQLServer"
    John

  • Convert comma separated string in rows

    Dear Gurus,
    I want to convert comma separated string in rows so as to insert in collection.
    e.g. string 1234,2323,23232,2343,34234
    Above string should be converted in rows so as to insert in table or collection
    Thanks in advance
    Sanjeev

    Or slight variation...
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select '1234,2323,23232,2343,34234' as txt from dual)
      2  --
      3  select REGEXP_SUBSTR (txt, '[^,]+', 1, level)
      4  from t
      5* connect by REGEXP_SUBSTR (txt, '[^,]+', 1, level) is not null
      6  /
    REGEXP_SUBSTR(TXT,'[^,]+',
    1234
    2323
    23232
    2343
    34234... so it doesn't have to work out how many levels it needs to do, it just keeps going until it get's a no-value (of course that assumes that there is always a value between each comma)

  • How to dynamically update columns in a where clause to a SQL query in OSB?

    Hi Gurus,
    I have a requirement where in we need to dynamically update a where clause to a SQL query in OSB(11.1.1.6.0).
    For example:
    If the JCA sql string is "select * from emp where emp_id = 100 and emp_status ='Permanent'" now i want to change this where clause and the new query has to be like "select * from emp where emp_name like 'S%' and emp_dept like 'IT' ". basically we need to change the where clause dynamically.
    We can also use "fn-bea:execute-sql()" in a xquery but I don't want to use this function as creates a new connection.
    I have done some home work and found out --> as per the DOC "http://docs.oracle.com/cd/E23943_01/dev.1111/e15866/jca.htm#OSBDV943" section: "25.5.2 JCA Transport Configuration for Proxy and Business Services", when a business service is created by using JCA, we can see Interaction Spec Properties under JCA Transport Tab. This will have a property "SqlString' and we can over ride it. But I am unable to figure out how to over ride the value. I have tried by using Transport Headers activity but no luck. Please guide me how to achieve this?
    Thanks in advance
    Surya

    I solved my problem.
    In my header renderer, I simply added a line to set the text to the object value "label.setText( (String) value );" (where label is an instance of a JLabel.
    Thank you to who took some time to think about it.
    Marc

Maybe you are looking for

  • Create view with dynamic from-clause

    Dear all, you might have some ideas to help me out of my issue that i just "created myself" ;-) i have a unknown and non-constant amount of tables using the the same table-structure and i do have a master table that contains all names of these kind o

  • Some suggestion for next version of iMac....

    Would be nice to have the ability to connect eSata devices to the iMac. Will there be a quad-core in future iMacs?

  • How do I change Ipad movie to photo?

    How can I change an IPad movie to a photo?

  • New Quoting System breaks HTML

    The new "email" style of quoting, in addition to being harder to read, breaks some HTML. Here's an example from this topic. Original: Matt, this section is for questions specifically about the new Discussions. You should repost your question here, an

  • Questions about shift register

    hello!When I use the shift register,A problem occur!what I want to use is the serial in shift register function,But found only use parallel shift register,someone can give me any suggestions?(The best way has an example of a serial shift register),th