Comparing 2 varchar fields

I have a procedure which accepts a varchar field as input and compares it with each value in a table. how do I code it.
e.g. proc1(xx IN varchar, yy OUT)
--say column name is abc then
where abc = xx;
Dosent giving any output.

here it goes
SQL> ED
Wrote file afiedt.buf
1 CREATE OR REPLACE PROCEDURE
2 COMPARE_VARCHAR_FIELDS(XX IN VARCHAR,YY OUT VARCHAR)
3 IS
4 A NUMBER:=0;
5 BEGIN
6 FOR I IN (SELECT * FROM AX WHERE X=XX)
7 LOOP
8 A:=A+1;
9 END LOOP;
10 IF A>0 THEN
11 YY:=XX||' FOUND '||A||' TIMES';
12 ELSE
13 YY:=XX||' NOT FOUND';
14 END IF;
15* END;
SQL> /
PL/SQL procedure successfully completed.
SQL> ed
Wrote file afiedt.buf
1 DECLARE
2 Z VARCHAR2(40);
3 BEGIN
4 COMPARE_VARCHAR_FIELDS('x',z);
5 dbms_output.put_line(z);
6* end ;
SQL> /
PL/SQL procedure successfully completed.
SQL> set serveroutput on
SQL> /
x FOUND 3 TIMES
PL/SQL procedure successfully completed.

Similar Messages

  • How to compare two fields from the same table in the select statement

    Hi, friends
    I try to compare tow fields from the same table, but no result,
    For example, this
    data: cptotchek tyep i.
    select count(*) into cptotchek
    from aufk where erdat = aufk-idat2 .
    The result is  cptotchek = 0, but there are the records in aufk , where,  aufk-erdat = aufk-idat2.
    Please, help me, i don't use the loop statement for optimize my program.
    Regards

    Hi  ,
           it will not return  any value   when you are using   column of same table 
           such as Date Field   , Because  while Using Aggregate Function  it will not check with self column
    .      For that you have to take data in one internal table and then you can work on it  .
         And if you are worried about Performance  it will not affect  , untill you are selecting only required data  .
    you can try this way  .
    data: cptotchek type i.
    types : begin of  w_aufk.
            include structure aufk  .
          types : end of  w_aufk .
    data : it_aufk type standard table of w_aufk with header line  .
    select * into corresponding fields of table it_aufk
    from aufk  .
    loop at it_aufk .
    if it_aufk-erdat  = it_aufk-idat2 .
    write : / it_aufk-erdat , it_aufk-idat2 .
    else .
    delete it_aufk .
    endif  .
    endloop.
    Regards
    Deepak.

  • Best practice to define length for varchar field of table in sql server

    What is best practice to define length for a varchar field in table
    where field suppose Remarks By Person  varchar(max) or varchar(4000)
    Could it affect on optimization in future????
    experts Reply Must ... 
    Dilip Patil..

    Hi Dilip,
    Varchar(n/max) is a variable-length, non-unicode character data. N defines the string length and can be a value from 1 through 8,000. Max indicates that the maximum storage size is 2^31-1 bytes (2 GB). The storage size is the actual length of the data entered
    + 2 bytes. We always use varchar when the sizes of the column data entries vary considerably. While if the filed data size might exceed 8,000 bytes in some way, we should use varchar(max).
    So the conclusion is just like Uri said, use varchar(max) or varchar(4000) is depends on how much characters we are going to store.
    The following document about varchar in SQL Server is for your reference:
    http://technet.microsoft.com/en-us/library/ms176089.aspx
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • How to compare two fields in condition editor in receiver determination

    Hello,
    Is it possible to compare to fields frrom the source in the condition editor of Receiver Determination?
    Because on the right hand operand we can specify only constants right and not the source field.
    For eg: If field1 != field2 then Reciever =  Receiver1
    Thanks,
    Loveena

    In standard receiver determination while defining the condition, you can only specify an element from the message payload using expression editor to create an expression for the left operand and you must specify a fixed value in the right operand, against which the value of the element will be compared at runtime. You can use only these (=,, ,EX) operators. So the functionalities are limited.
    so you have to use Enhanced Receiver Determination, In this Instead of creating the receivers in the receiver determination manually, you assign an Interface mapping to the receiver determination and this returns a list of receivers at runtime.
    refer this wiki for more details
    http://wiki.sdn.sap.com/wiki/pages/viewpage.action?pageId=133562771

  • Clob's versus Varchar fields

    It's been a day of learning. I found out that when Kodo gets a
    columnlength of -1 for a String field, it will ask the Dictionary for
    the sql for generating a Clob. Also when Kodo finds a positive
    columnlength it will call getLenString on the dictionary.
    We're using MySQL and in this case, when the column-length of a String
    is set to -1 this creates a TEXT field and when the column-length is
    positive this creates a VARCHAR(column-length) field.
    When querying the database, Kodo once again turns to the meta data. When
    the column-length has been set to -1 Kodo does a separate query for each
    text field. If the column-length is positive, Kodo includes the field in
    it's default-fetch-group.
    Am I correct so far?
    The problem I have is that when a query for a certain field is
    performed, I want it to be in the first group fetched. It is always
    needed and not that large at all. It will at most be 1500 characters. In
    SQL Server and possibly others, I can put the column-length at 1500 and
    wind up with a varchar field of 1500 characters long. MySQL however,
    does not support anything over 255 characters for a varchar field.
    So, I need to create a field of type TEXT to allow it to contain more
    than 255 chars. However, I do not want a separate query for the field
    since it won't be that big anyway.
    I've been able to get this working using the column-length -1 at schema
    time and the value 1500 at runtime. This is not at all convenient and
    will very likely result in a wrong schema being created or the wrong
    query being run in the long run.
    Is the solution I just mentioned the only one, or are there other scenarios?
    Thanks in advance,
    Martin van Dijken

    Martin-
    Your analysis is exactly right. Kodo 3.0 allows a lot more latitude in
    how this behavior is defined.
    One way in which you might be able to get around this problem is to
    leave the "column-length" attribute to -1, but manually force the
    mapping to not be the ClobMapping (which is the mechanism by which Kodo
    knows to issue a separate query for the object). You can do this by
    setting the "custom-mapping" field-level metadata extension to
    "com.solarmetric.kodo.impl.jdbc.ormapping.ValueMapping".
    I'll be interested to know if this works for you.
    In article <[email protected]>, Martin van Dijken wrote:
    It's been a day of learning. I found out that when Kodo gets a
    columnlength of -1 for a String field, it will ask the Dictionary for
    the sql for generating a Clob. Also when Kodo finds a positive
    columnlength it will call getLenString on the dictionary.
    We're using MySQL and in this case, when the column-length of a String
    is set to -1 this creates a TEXT field and when the column-length is
    positive this creates a VARCHAR(column-length) field.
    When querying the database, Kodo once again turns to the meta data. When
    the column-length has been set to -1 Kodo does a separate query for each
    text field. If the column-length is positive, Kodo includes the field in
    it's default-fetch-group.
    Am I correct so far?
    The problem I have is that when a query for a certain field is
    performed, I want it to be in the first group fetched. It is always
    needed and not that large at all. It will at most be 1500 characters. In
    SQL Server and possibly others, I can put the column-length at 1500 and
    wind up with a varchar field of 1500 characters long. MySQL however,
    does not support anything over 255 characters for a varchar field.
    So, I need to create a field of type TEXT to allow it to contain more
    than 255 chars. However, I do not want a separate query for the field
    since it won't be that big anyway.
    I've been able to get this working using the column-length -1 at schema
    time and the value 1500 at runtime. This is not at all convenient and
    will very likely result in a wrong schema being created or the wrong
    query being run in the long run.
    Is the solution I just mentioned the only one, or are there other scenarios?
    Thanks in advance,
    Martin van Dijken
    Marc Prud'hommeaux [email protected]
    SolarMetric Inc. http://www.solarmetric.com

  • Dividing sum of varchar fields?

    I'm using SQL Server 2014 and I have the following table containing two varchar fields I need to sum and divide:
    CREATE TABLE.[VMs](
    [VMID] [int] IDENTITY(1,1) NOT NULL,
    [vCenter] [varchar](100) NULL,
    [VMName] [varchar](100) NULL,
    [Template] [varchar](100) NULL,
    [PowerState] [varchar](100) NULL,
    [ClusterName] [varchar](100) NULL,
    [Disk] [int] NULL,
    [DiskPartition] [varchar](70) NULL,
    [DiskSizeGB] [decimal](10, 3) NULL,
    [Hostname] [varchar](100) NULL,
    CONSTRAINT [PK_VMs] PRIMARY KEY CLUSTERED
    [VMID] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    I'm trying to get the distinct sum of 'VMName' and 'Hostname' to get the count of each, and then divide the 'VMName' count by 'Hostname' count on a per 'vCenter' basis.
    I'm not sure how to perform calculations against the varchar fields and any help would be appreciated.
    Thanks in advance
    Adam

    This is the main query, the top portion was sample data I just put based on your provided data
    ;With CTE
    AS
    SELECT
    vCenter
    ,COUNT(DISTINCT VMName) As CountVMName
    ,COUNT(DISTINCT HostName) As CountHostName
    FROM
    @myTable
    GROUP BY
    vCenter
    SELECT *, (CASE WHEN CountHostName <> 0 THEN CountVMName / CountHostName ELSE 0 END) As CountPerVCenter
    FROM
    CTE
    Best Wishes, Arbi; Please vote if you find this posting was helpful or Mark it as answered.

  • Converting varchar field to date

    I got a varchar field in DB with format YYYY/MM/DD HH:MI:SS in DB . I want to convert this to date field in RPD. When I did
    CAST ( VarChar field AS DATE) in RPD it is not working I am getting sql error.
    Thanks for your help.

    Hi,
    can you try once to cast your char as a timestamp.
    Hope that works.
    Kr,
    A

  • Automatically trim a varchar field in an update SQL

    We have an ETL application that does an update with a varchar field. When the field contains spaces, we see that with an update these spaces are trimmed automatically. We wonder whether there is a HANA setting that can be set to disable this trim....

    For your ETL, Is HANA the source system?
    If yes, then you got to change at ETL side right?
    Regards,
    Krishna Tangudu

  • Using a varchar field as number on ui

    Hello
    In one of the requirements we got to use a varchar field in db to store as number in UI. The user may specify + or - in the begining and it can be number up to 2 decimal places.
    So, how to achieve this?
    We are using jdev 11.1.1.6.2

    may be have a transient field with number datatype and use af:convertNumber with minFractionDigits and maxFractionDigits to 2. it would take - not sure about + sign (might remove automatically). convert this as string and try saving it with your actual field.

  • Getting all VARCHAR fields with string length different then x

    Hello,
    I am trying to get from a table all the rows which contain in a certain varchar field a string length different than x (5 i.e.):
    varchar field
    treds
    fd <-
    grgrt
    sdfsdfsdf <-
    fdsds
    the marked rows will been given out.
    Thanks!

    Term, the Oracle SQL manual contains documentation on the Oracle functions. Most of the functions can be classified as either character functions, number (math) functions, date functions, and conversion functions.
    If you are going to work with Oracle you will benefit from looking on the list of available functions to become familiar with what is available.
    HTH -- Mark D Powell --

  • I would like to compare two field and then is it's true then the output will be the 2nd one

    Hello All,
    I am doing a mappong where i need to compare two field and then if there are equal the 2nd one should be the output and 2nd value will be using multiple segment.
    It's for shipment.
    Regards
    Rituparna

    Not sure if i understand correctly. But you are trying to compare one field with multiple occurrences of another field.
    You can make use of the node function "Use One as Many" and repeat the first value as many times as the second value.
    Please refer to below wiki.
    Explain node functions - Process Integration - SCN Wiki

  • Comparing the fields of one file to another file

    Hi guys,
    Is it possible to compare the fields of one file to another file using ABAP?
    I have a file extracted from SAP and I want to compare my extracted file to another file using ABAP?
    How am I going to do it?
    Thanks a lot!
    Rgds,
    Mark

    Mark,
    How to read the file from appli. server to internal table:
    DATA : v_fpath TYPE salfile-longname VALUE
                                   '/data/sapdata/inc/inbox/ppm_maint_plan'.
    DATA : BEGIN OF i_records OCCURS 0,
            rec TYPE string ,
          END OF i_records.
    DATA : BEGIN OF it_input,
                 tplnr LIKE iflot-tplnr,
                 stjobno(22),
                date1(10),
                frequency(10),
                sortfield(20),
                ilart LIKE t353i-ilart,
            END OF it_input.
    OPEN DATASET v_fpath  FOR INPUT IN TEXT MODE.
        DO.
          READ DATASET v_fpath_te INTO i_records-rec .
          IF sy-subrc EQ 0.
              SPLIT i_records-rec AT c_coma INTO it_input-tplnr
                                                 it_input-stjobno
                                                 it_input-date1
                                                 it_input-frequency
                                                 it_input-sortfield
                                                 it_input-ilart.
              APPEND it_input.
              CLEAR it_input.
          ELSE.
            EXIT.
          ENDIF.
        ENDDO.
        CLOSE DATASET v_fpath .
    Note :  it_input is the internal table .If you don't know the columns structure.Declare your internal table (it_input ) fileds as "char" with some length.
    Do same thing for another file.
    SORT : both internal tables.
    LOOP AT it_input.
      LOOP AT SECON_internaltable.
        compare the fields here..
      ENDLOOP.
    ENDLOOP.
    Pls. reward if useful....

  • Do you know of a standard tool to compare the fields of 2 database tables?

    do you know of a standard tool to compare the fields of 2 database tables? please note i dont want to compare data just the fields.
    ~Suresh

    Hi,
    I am not aware any standard tool but you can write custom report to use FM DDIF_FIELDINFO_GET to get fields information of SAP database table.
    Call the above FM twice in order to get field names for two different database tables. Then compare the results (table parameter DFIES_TAB) to find out the differences of field names.
    Hope this will help ...
    Regards,
    Ferry Lianto

  • Compare two fields of one table in selection.

    Dear Experts,
    I want to compare two fields of a table and make selection according to this.
    Ex: simply i want to select the rows from table mard where mard-labst>mard-insme. Could you write me the code to make this selection.

    Yes, Thomas,
    Its working:
    Sample code:
    data: begin of itab occurs 0,
          matnr type matnr,
          ernam type ernam,
          end of itab.
    select matnr ernam
           into table itab
           from mara where brgew > mara~ntgew.
    loop at itab.
      write: itab-matnr.
    endloop.
    Or,
    Try with inner join once.
    Its working: Sample code.
    data: begin of itab occurs 0,
          matnr type matnr,
          ernam type ernam,
          end of itab.
    select p~matnr q~ernam
           into table itab
           from mara as p
           inner join mara as q
           on p~brgew > q~ntgew.
    loop at itab.
      write: itab-matnr.
    endloop.
    Thanks,
    Naveen.I

  • Is there is any  way to create a validator to compare two fields (like a pa

    Hi,
    Is there is any way to create a validator to compare two fields (like a password and a retype password ) ?
    please give me any suggestion or any example related this problem!!
    thanks,
    Praveen Soni

    Ugh, do you have taken over the LimitValidator and the JSF example (including the f:validateDoubleRange which is unnecessary in this case) literally without actually reading/interpreting/understanding it? No, then it is indeed not going to work. Basically you just need to define a validator in the one password field and pass the client ID of the another field as attribute along the one password field. In the validator you can retrieve the value of the another field by its client ID and finally just invoke String#equals() on the values of the both fields.

Maybe you are looking for