How to compare string in a table reg

Hi all,
I need a solution of this requirement.
i have Table reqtab
Code sql:
sql>select * FROM reqtab;
REID EMAILADDRESS
72 [email][email protected][email]
72 [email][email protected][email]
75 [email][email protected][email]
75 [email][email protected][email]
now the requirement is:
---> i have to create a procedure which should takes 72, 75 as in parameter
and these procedure should compare emailaddress of 72, 75 and if this emailaddresses are not matching ,should update with unique mailids
for 72
i need the table should be updated in the following way
result should be
Code sql:
REID EMAILADDRESS
72 [email][email protected][email]
72 [email][email protected][email]
72 [email][email protected][email]
Thanks n Regards
Laxman

LAX_ORA wrote:
Hi all,
I need a solution of this requirement.
i have Table reqtab
Code sql:
sql>select * FROM reqtab;
REID EMAILADDRESS
72 [email][email protected][email]
72 [email][email protected][email]
75 [email][email protected][email]
75 [email][email protected][email]
now the requirement is:
---> i have to create a procedure which should takes 72, 75 as in parameter
and these procedure should compare emailaddress of 72, 75 and if this emailaddresses are not matching ,should update with unique mailids
for 72
i need the table should be updated in the following way
result should be
Code sql:
REID EMAILADDRESS
72 [email][email protected][email]
72 [email][email protected][email]
72 [email][email protected][email]
Thanks n Regards
LaxmanYou're talking of a combination of updates and deletes to your table.
You can define a query that can determine what action needs to be taken for each record e.g.
SQL> ed
Wrote file afiedt.buf
  1  with t as (select 72 as reid, '[email][email protected][/email]' as emailaddress from dual union all
  2             select 72, '[email][email protected][/email]' from dual union all
  3             select 75, '[email][email protected][/email]' from dual union all
  4             select 75, '[email][email protected][/email]' from dual)
  5  --
  6  -- END OF TEST DATA
  7  --
  8      ,req as (select 72 as reid from dual union all
  9               select 75 from dual)
10      ,mreq as (select min(reid) as reid from req)
11  --
12  select t.reid, t.emailaddress, case when mreq.reid = t.reid then 'No Action'
13                                      when mreq.reid < t.reid and row_number() over (partition by t.emailaddress order by t.reid) =1 then 'Update to '||mreq.reid
14                                 else 'Delete'
15                                 end as action
16  from   t       join req on (t.reid = req.reid)
17           cross join mreq
18* order by 2
SQL> /
      REID EMAILADDRESS              ACTION
        72 [email][email protected][/email]  No Action
        75 [email][email protected][/email]  Delete
        72 [email][email protected][/email] No Action
        75 [email][email protected][/email]  Update to 72
SQL>... and then action each of those as required.
Doing it in this way, having your required REID values in a table (temporary table or whatever) will allow the query to work for any number of such values e.g. here's an example with 3 of them...
SQL> ed
Wrote file afiedt.buf
  1  with t as (select 72 as reid, '[email][email protected][/email]' as emailaddress from dual union all
  2             select 72, '[email][email protected][/email]' from dual union all
  3             select 75, '[email][email protected][/email]' from dual union all
  4             select 75, '[email][email protected][/email]' from dual union all
  5             select 77, '[email][email protected][/email]' from dual union all
  6             select 77, '[email][email protected][/email]' from dual)
  7  --
  8  -- END OF TEST DATA
  9  --
10      ,req as (select 72 as reid from dual union all
11               select 75 from dual union all
12               select 77 from dual)
13      ,mreq as (select min(reid) as reid from req)
14  --
15  select t.reid, t.emailaddress, case when mreq.reid = t.reid then 'No Action'
16                                      when mreq.reid < t.reid and row_number() over (partition by t.emailaddress order by t.reid) =1 then 'Update to '||mreq.reid
17                                 else 'Delete'
18                                 end as action
19  from   t       join req on (t.reid = req.reid)
20           cross join mreq
21* order by 2
SQL> /
      REID EMAILADDRESS              ACTION
        72 [email][email protected][/email]  No Action
        75 [email][email protected][/email]  Delete
        77 [email][email protected][/email]  Delete
        72 [email][email protected][/email] No Action
        75 [email][email protected][/email]  Update to 72
        77 [email][email protected][/email]  Update to 72
6 rows selected.
SQL>

Similar Messages

  • Compare String in a table and insert the common values into a New table

    Hi all,
    Anyone has idea on how to compare a string value in a table.
    I have a Students Table with Student_id and Student_Subject_list columns as below.
    create table Students( Student_id number,
    Student_Subject_list varchar2(2000)
    INSERT INTO Students VALUES (1,'Math,Science,Arts,Music,Computers,Law,Business,Social,Language arts,History');
    INSERT INTO Students VALUES (2,'Math,Law,Business,Social,Language arts,History,Biotechnology,communication');
    INSERT INTO Students VALUES (3,'History,Spanish,French,Langage arts');
    INSERT INTO Students VALUES (4,'History,Maths,Science,Chemistry,English,Reading');
    INSERT INTO Students VALUES (5,'Math,Science,Arts,Music,Computer Programming,Language arts,History');
    INSERT INTO Students VALUES (6,'Finance,Stocks');
    output
    Student_id     Student_Subject_list
    1     Math,Science,Arts,Music,Computers,Law,Business,Social,Language arts,History
    2     Math,Law,Business,Social,Language arts,History,Biotechnology,communication
    3     History,Spanish,French,Langage arts
    4     History,Maths,Science,Chemistry,English,Reading
    5     Math,Science,Arts,Music,Computer Programming,Language arts,History
    6     Finance,Stocks
    I need help or some suggestion in write a query which can compare each row string value of Student_Subject_list columns and insert the
    common subjects into a new table(Matched_Subjects).The second table should have the below colums and data.
    create table Matched_Subjects(Student_id number,
    Matching_studesnt_id Number,
    Matched_Student_Subject varchar2(2000)
    INSERT INTO Matched_Subjects VALUES (1,2,'Math,Law,Business,Social,Language arts,History');
    INSERT INTO Matched_Subjects VALUES (1,3,'History,Langage arts');
    INSERT INTO Matched_Subjects VALUES (1,4,'History,Maths,Science');
    INSERT INTO Matched_Subjects VALUES (1,5,'Math,Science,Arts,Music,Language arts,History');
    INSERT INTO Matched_Subjects VALUES (2,3,'History,Langage arts');
    INSERT INTO Matched_Subjects VALUES (2,4,'History,Maths');
    INSERT INTO Matched_Subjects VALUES (2,5,'Math,Language arts,History');
    INSERT INTO Matched_Subjects VALUES (3,4,'History');
    INSERT INTO Matched_Subjects VALUES (3,5,'Language arts,History');
    INSERT INTO Matched_Subjects VALUES (4,5,'Math,Science');
    output:
    Student_id      Match_Student_id     Matched_Student_Subject
    1     2     Math,Law,Business,Social,Language arts,History
    1     3     History,Langage arts
    1     4     History,Maths,Science
    1     5     Math,Science,Arts,Music,Language arts,History
    2     3     History,Langage arts
    2     4     History,Maths
    2     5     Math,Language arts,History
    3     4     History
    3     5     Language arts,History
    4     5     Math,Science
    any help will be appreciated.
    Thanks.
    Edited by: user7988 on Sep 25, 2011 8:45 AM

    user7988 wrote:
    Is there an alternate approach to this without using xmlagg/xmlelement What Oracle version are you using? In 11.2 you can use LISTAGG:
    insert
      into Matched_Subjects
      with t as (
                 select  student_id,
                         column_value l,
                         regexp_substr(student_subject_list,'[^,]+',1,column_value) subject
                   from  students,
                         table(
                               cast(
                                    multiset(
                                             select  level
                                               from  dual
                                               connect by level <= length(regexp_replace(student_subject_list || ',','[^,]'))
                                    as sys.OdciNumberList
      select  t1.student_id,
              t2.student_id,
              listagg(t1.subject,',') within group(order by t1.l)
        from  t t1,
              t t2
        where t1.student_id < t2.student_id
          and t1.subject = t2.subject
        group by t1.student_id,
                 t2.student_id
    STUDENT_ID MATCHING_STUDESNT_ID MATCHED_STUDENT_SUBJECT
             1                    2 Math,Law,Business,Social,Language arts,History
             1                    3 Language arts,History
             1                    4 Science,History
             1                    5 Math,Science,Arts,Music,Language arts,History
             2                    3 Language arts,History
             2                    4 History
             2                    5 Math,Language arts,History
             3                    4 History
             3                    5 History,Language arts
             4                    5 History,Science
    10 rows selected.
    SQL> Prior to 11.2 you can create your own string aggregation function STRAGG - there are plenty of example on this forum. Or use hierarchical query:
    insert
      into Matched_Subjects
      with t1 as (
                  select  student_id,
                          column_value l,
                          regexp_substr(student_subject_list,'[^,]+',1,column_value) subject
                    from  students,
                          table(
                                cast(
                                     multiset(
                                              select  level
                                                from  dual
                                                connect by level <= length(regexp_replace(student_subject_list || ',','[^,]'))
                                     as sys.OdciNumberList
           t2 as (
                  select  t1.student_id student_id1,
                          t2.student_id student_id2,
                          t1.subject,
                          row_number() over(partition by t1.student_id,t2.student_id order by t1.l) rn
                    from  t1,
                          t1 t2
                    where t1.student_id < t2.student_id
                      and t1.subject = t2.subject
      select  student_id1,
              student_id2,
              ltrim(sys_connect_by_path(subject,','),',') MATCHED_STUDENT_SUBJECT
        from  t2
        where connect_by_isleaf = 1
        start with rn = 1
        connect by student_id1 = prior student_id1
               and student_id2 = prior student_id2
               and rn = prior rn + 1
    STUDENT_ID MATCHING_STUDESNT_ID MATCHED_STUDENT_SUBJECT
             1                    2 Math,Law,Business,Social,Language arts,History
             1                    3 Language arts,History
             1                    4 Science,History
             1                    5 Math,Science,Arts,Music,Language arts,History
             2                    3 Language arts,History
             2                    4 History
             2                    5 Math,Language arts,History
             3                    4 History
             3                    5 History,Language arts
             4                    5 History,Science
    10 rows selected.SY.

  • How to compare data between two tables?

    Hi,
    My team is trying to develop a SAP data migration tool (DMT) using ABAP.
    One of the functionalities in the DMT is to validate the data in the staging area against the loaded SAP data.
    The tables in the stagin area are customer tables (i.e. user-defined tables starting with Y, Z).
    How do I compare the data in the staging area against data that are loaded into SAP tables? Are there some built-in SAP functions to do this? Or, are there some better ways of doing this (e.g. instead of comparing against data in the SAP tables, we compare with some INTERNAL tables)?
    Any help would be greatly appreciated, thanks!

    Hi Kian,
    Use <b>SCMP</b> transaction to compare data between two tables and you can not use this for comparing internal tables.
    Thanks,
    Vinay

  • How to compare two records of table

    Hi all,
    How to compare new record with all existing records in table.
    In my application i have status column ,which contains the information about
    the record is new or old record .
    thank you

    /*does record 1 have friend*/
    WITH t AS
    (SELECT 1 AS Id, 'a' AS NAME, 'type1' AS Col
      FROM Dual
      UNION ALL
      SELECT 2 AS Id, 'a' AS NAME, 'type1' AS Col
      FROM Dual
      UNION ALL
      SELECT 3 AS Id, 'a' AS NAME, 'type2' AS Col FROM Dual)
    SELECT count(*) as YesNo
    FROM t T1
    WHERE T1.Id = 1
          AND (T1.Name, T1.Col) IN (SELECT T2.Name, T2.Col FROM T t2 where t2.ID != T1.Id);
         1
    /*does record 3 have friend*/
    WITH t AS
    (SELECT 1 AS Id, 'a' AS NAME, 'type1' AS Col
      FROM Dual
      UNION ALL
      SELECT 2 AS Id, 'a' AS NAME, 'type1' AS Col
      FROM Dual
      UNION ALL
      SELECT 3 AS Id, 'a' AS NAME, 'type2' AS Col FROM Dual)
    SELECT count(*) as YesNo
    FROM t T1
    WHERE T1.Id = 3
       AND (T1.Name, T1.Col) IN (SELECT T2.Name, T2.Col FROM T t2 where t2.ID != T1.Id);
         0
    */

  • How to compare string in a case-insensitive manner using JavaScript?

    Hello everyone,
    Now I have a javascript to compare checkbox's value with user's input, but now seems it only can compare case-sensitively, does some one know if there is a function in javascript that it can compare string case-insensitively ?
    Here is my script :
    function findOffice(field)
    var name;
    name=prompt("What is the office name?");
    var l = field.length;
    for(var i = 0; i < l; i++)
    if(field.value==name)
    field[i].checked=true;
    field[i].focus();
    field[i].select();
    break;
    <input type="button" name="Find" value="Find And Select" onClick="findOffice(form1) >
    Thanks in advance !
    Rachel

    Thank you so much, I already solved the problem with your advice.
    You really have a beautiful mind, :-).
    I appreciate your help !
    Rachel

  • How to compare substring in two tables fields

    Hi ABAP expert,
    When I want to select database two tables, we just want to compare two table substring. For Example, both fields have yyyymmdd. But I have interested yyyymm. In the Oracle database and SQL server database, I can easily to use substr to achieve those goals. How in the ABAP program to archive those goals.
    Thanks in advance,
    Cliff Fan

    Hi you can access substrings in ABAP the following way:
    data: s type string value 'yyyymmdd'.
    write: / s(6). "yyyymm
    write: / s+4(4). "mmdd
    so the number after '+' determines the position in the string and the number in parenthesis () determines the length of the substring.
    Now you can just loop over both of your tables and perform the necessary comparison in the nested loop.

  • How to populate string array in table view.

    Hi,
    By using webservice i am able to get an array of strings but, I am unable to populate those values in the tableview.
    Can any one please suggest me how to populate array of strings in table view with an example.
    Thanks,
    SRI.

    Search this forum. You will find plenty of threads on the same...
    Raja

  • Newbie Question: Rules: Functions: How to compare String based type?

    I have some XML facts in my rules dictionary defined by the following schema (fragments shown)
    <xs:simpleType name="VarType">
       <xs:restriction base="xs:string">
          <xs:enumeration value="Foo"/>
          <xs:enumeration value="Bar"/>
          <xs:enumeration value="Baz"/>
          <xs:enumeration value="Qux"/>
       </xs:restriction>
    </xs:simpleType>
    <xs:complexType name="ProgType">
       <xs:sequence>
          <xs:element name="ID" type="xs:string"/>
          <xs:element name="var" type="VarType" maxOccurs="unbounded"/>
       </xs:sequence>
    </xs:complexType>
    Which means that a Prog of ProgType has an ID and a "list" of "var" strings restricted to bounds specified by VarType.
    The issue comes when I try to create a Rules Function operating on these types.
    Function-> boolean containsVar(ProgType prog,VarType var) (built using the Functions tab of the Rules editor)
    for (String v : prog.var ){
       if (v == var){
          return true
    return false
    The problem we run into here is typing. If v is declared a String, as here, then v == var is invalid because types don't match. But I can't declare v a VarType due to
    RUL-05583: a primitive type or fact type is expected, but neither can be found.
    This problem may stem from the fact the Java's String is declared final and can't be subclassed, so the JAXB translation to Java may have to wrap it, futzing ==/equals() in the process.
    SO... How do I create this method and compare these values?
    TIA
    Edited by: wylderbeast on Mar 10, 2011 9:15 AM - typos
    Edited by: wylderbeast on Mar 10, 2011 9:18 AM

    And here's the answer.
    var.value() seems to return the String value of the type
    so the comparison becomes
    (v == var.value())
    Live and learn....

  • How to compare strings ignoring accents?

    Hi all,
    I'd like to know, how can I compare 2 strings, ignoring accents.
    i.e.: caf? should be come before cafo, and caf? should be considered the same word as cafe
    Message was edited by:
    Valeriano

    hint: strength
    import java.text.*;
    import java.util.*;
    public class CollatorExample {
        public static void main(String[] args) {
            test(Collator.PRIMARY, "PRIMARY");
            test(Collator.SECONDARY, "SECONDARY");
            test(Collator.TERTIARY, "TERTIARY");
            test(Collator.IDENTICAL, "IDENTICAL");
        static void test(int strength, String strengthName) {
            Collator c = Collator.getInstance(Locale.FRENCH);
            c.setStrength(strength);
            System.out.println(strengthName + " : " + c.compare("caf?", "cafe"));
    }

  • How to split string in data table row in c#

    hi,
    Binding List data in to data table,. in that table i have description column. this column data move to data table in sql server
    here we facing problem for Description column
    the description column having data is
    <div class="ExternalClassE4908D8C25DF4D1586D0A010BFBC5A53">3400</div>
    now we want only 3400 values i am using this code
    ring Descrption = rows["Description"].ToString();
    if (! string.IsNullOrEmpty(Descrption))
    char[] splitString = new char[] { '<', '>' };
    string[] parts = Descrption.Split(splitString,
    StringSplitOptions.RemoveEmptyEntries);
    // string[] Dec_1 = Dec.Split(new char[] { '<' }, StringSplitOptions.RemoveEmptyEntries);
    rows["Description"] = parts[1].ToString();

    Hope the below helps as start..Modify 
    //Option1
    Descrption = Descrption.Substring(0, Descrption.LastIndexOf("<"));
    Descrption = Descrption.Substring(Descrption.LastIndexOf(">") + 1);
    Console.WriteLine(" {0} ", Descrption);
    //Option2
    Console.WriteLine(" {0} ", Regex.Replace(Descrption, "<[^>]*>", string.Empty));
    accordingly..

  • How to compare table's date field with dropdown year field

    Hi All,
    I have one requirement to display the selected rows from a database table based on the selection of drop down.
    Here, I have one dropdown of year(like 2009,2010,....) and I have one database table which contains one field with "DATE".
    Now, I want to compare table's DATE field with my dropdown field.
    Problem is that table's DATE field is of type "DATS" and dropdown is of type INTEGER(or) STRING ...
    How to compare this fields?
    Can any one please give me solution for this...!
    Thanks in Advance!

    Hi  sreelakshmi.B,
    try the following:
    DATA lt_dats        TYPE TABLE OF dats.
    DATA l_dat_i        TYPE          i.
    DATA l_dat_c_4(4)   TYPE          c.
    DATA l_dat_c_12(12) TYPE          c.
    DATA l_dats_from    TYPE          dats.
    DATA l_dats_to      TYPE          dats.
    *Move Date from Integer to Char
    l_dat_c_4 = l_dat_i = 2005.
    *Create Date From use in WHERE-Clause
    CONCATENATE '01.01.' l_dat_c_4 INTO l_dat_c_12.
    CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
         EXPORTING
              date_external            = l_dat_c_12
         IMPORTING
              date_internal            = l_dats_from
         EXCEPTIONS
              date_external_is_invalid = 1
              OTHERS                   = 2.
    IF sy-subrc <> 0.
    ENDIF.
    *Create Date To use in WHERE-Clause
    CONCATENATE '31.12.' l_dat_c_4 INTO l_dat_c_12.
    CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
         EXPORTING
              date_external            = l_dat_c_12
         IMPORTING
              date_internal            = l_dats_to
         EXCEPTIONS
              date_external_is_invalid = 1
              OTHERS                   = 2.
    IF sy-subrc <> 0.
    ENDIF.
    * Select records in range
    SELECT *
           FROM [DBTAB]
           INTO TABLE [ITAB]
           WHERE [DATE] BETWEEN l_dats_from
                        AND     l_dats_to.
    Regards
    REA

  • How to compare records in singe internal table

    Hi Folks,
    iam having 3 records in my first itab( T_FINAL) with fields
    material no,  descrip ,  mat type and  group.
    and 16 records in second itab(T_MVKE ) with fields
    mat no ,  distri.chanel  and division
    now I want to fetch the records from T_MVKE  by comparing the records in
    T_FINAL .my requirement is to check the given mat no. in sales org.2000,2100.  if yes then i have to consider 2000 only, if it is in only 2100 then consider 2100 only . is it is in 2000 only then consider 2100 only
    my code is
    LOOP AT T_FINAL.
        READ TABLE T_MVKE WITH KEY MATNR = T_FINAL-MATNR.
       IF SY-SUBRC = 0.
       ON CHANGE OF T_MVKE-MATNR OR T_MVKE-VKORG.
    IF T_MVKE-VKORG = '2000' and SY-TABIX > 1.
          CONCATENATE '2000' 'TS' P_WERKS T_FINAL-MATNR INTO KEY.
    ELSEIF T_MVKE-VKORG = '2000' AND SY-TABIX = 1.
         CONCATENATE '2000' 'TS' P_WERKS T_FINAL-MATNR INTO KEY.
    ELSE.
        CONCATENATE '2100' 'TS' P_WERKS T_FINAL-MATNR INTO KEY.
        ENDIF.
    this logic fails ,. could tell me how to compare values in single itab?
    Thanks
    neha

    Hi ,
    if i've understand you correctly , try that:
    LOOP AT t_final.
      AT NEW matnr.
        CLEAR: v_2000, v_2100.
    *1) 2000
        READ TABLE  t_mvke    WITH KEY matnr = t_final-matnr
                                       vkorg = 2000.
        IF sy-subrc = 0.
          v_2000 = 'X'.
        ENDIF.
    *2) 2100
        READ TABLE  t_mvke    WITH KEY matnr = t_final-matnr
                                       vkorg = 2100.
        IF sy-subrc = 0.
          v_2100 = 'X'.
        ENDIF.
    *compare
        IF v_2000 = 'X' AND  v_2100 = 'X'.
    *read 2000 only
        ELSEIF v_2000 = ' '  AND v_2100 = ' '.
    *nothing found
        ELSE.
    *all other combinations
    *read 2100 only
        ENDIF.
      ENDAT.
    ENDLOOP.
    regards Andreas

  • How to compare values in table control

    Hi Experts,
    How to compare two values of a field in table control. Like the frist row of feld1 with the second row of field1.
    because when ever two values are same i need to display error message that we are entring duplicate entry.
    i have been tring for a very log time but not getting any solution for this.
    Thanks and Regards,
    Ashwin.

    you need to write in code for this..
    A possible solution is given below..
    Suppose your internal table fields are col1 and col2.
    in the loop .....endloop of yout internal table in your PAI..there will be  following(if your table control is made using wizard. otherwise you might have to add it..
    loop at itab.
    chain.
    field col1.
    field col2.
    "some module
    endchain.
    endloop.
    now make changes as shown to the above code..
    loop at itab.
    chain.
    field wa-col1.
    field wa-col2.
    module table_modify on chain-request.
    endchain.
    now in your program add module table modify.
    module table_modify input.
    read table itab with key col1(which shud be unique) = wa-col1 transporting no-fields.
    if sy-subrc = 0. " there exists another record with the same value
    message e001(your message class).
    endif.
    endmodule.
    i guess that shud work. get back if it dosnt.
    regards
    Suzie

  • How to compare Date/time string

    I read from datalog file including Date/time string ,and want to query the special Date/time string span ,how to compare the data/time string ?

    Hello Joshua,
    To compare date/time you have to extract the different components (day, month, year, hour, minute, second) anyway. Why not "convert to seconds"? I think it's easier to compare one number (where you also can do other math, like calc the difference and so on) than to compare seven (?) parameters with some exceptions... If the dates are read from excel (there was a similar thread some days ago), why not convert to seconds in excel (just a format change)?
    Best regards,
    GerdW
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • How to compare 2 different database to get table name which are not present in second database

    How to compare 2 different database to get table name which are not present in second database

    Sorry cannot test it right now
    use db1
    go
    select * from sys.tables t where not exists
    (select * from db2.sys.tables s where t.object_id=s.object_id)
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

Maybe you are looking for