Avoid Repating values using SQL

Hi team,
I have this issue here which i am finding difficult to handle it, after my stint with SAP,
Case1
Col1         col2          col3         Qty
97812799     65021329     45019836     48492
85001060     65021329     45019836     48492
*Now i want that QTY column should only have single value i.e. 48492, either in first row or 2nd row doesnt matter, but we have have only one value*
_expected result_
Col1          col2         col3         Qty
97812799     65021329     45019836     48492
85001060     65021329     45019836     
Case 2
Col1          col2          col3         Qty
85001133     65021369     45019878     76169
85001132     65021369     45019878     76169
97813988     65021369     45019878     76169
97813003     65021369     45019878  76169
Expected result
Col1          col2         col3         Qty
85001133     65021369     45019878     76169  --> could be anywhere in the record list, but need to have only 1 value
85001132     65021369     45019878     
97813988     65021369     45019878     
97813003     65021369     45019878
plz assist me here, or give me hints i would try my self,
Kind regardsEdited by: Nicloei W on Apr 14, 2010 6:38 PM

The column with the distinct values will be always the same (col1)?
If so, could be this:
Connected to Oracle Database 11g Enterprise Edition Release 11.1.0.6.0
Connected as fsitja
SQL>
SQL> with t as (
  2  select 85001133 col1, 65021369 col2, 45019878 col3, 76169 qty from dual union all
  3  select 85001132, 65021369, 45019878, 76169 from dual union all
  4  select 97813988, 65021369, 45019878, 76169 from dual union all
  5  select 97813003, 65021369, 45019878, 76169 from dual union all
  6  select 97812799, 65021329, 45019836, 48492 from dual union all
  7  select 85001060, 65021329, 45019836, 48492 from dual
  8  )
  9  -- end of sample data
10  SELECT col1, col2, col3, decode(rn, 1, qty) qty
11    FROM (SELECT col1, col2, col3, qty, row_number() over(PARTITION BY col2, col3 ORDER BY col1) rn FROM t)
12   ORDER BY col2, col3, col1;
      COL1       COL2       COL3        QTY
  85001060   65021329   45019836      48492
  97812799   65021329   45019836
  85001132   65021369   45019878      76169
  85001133   65021369   45019878
  97813003   65021369   45019878
  97813988   65021369   45019878
6 rows selected
SQL>

Similar Messages

  • Default form value using sql with bind variable

    I wish to create a form based upon a table with a foreign key. I wish to add a field to the form that is an uneditable text field with a default value using sql of 'select name from other_table where other_table_id = ?' where ? is a bind variable defined by a hidden field which is the value of the foreign key identified at runtime. How can this be done?
    null

    I don't think that will work. I have multiple people accessing the Portal at the same time with the same login (or lack of as public will be the most common user). I could set it easily enough as the value is passed to the form by a link object, so I could add it to the before page plsql block and set the value. But I am uncertain how it will behave in a multi-user mutlitasking environment.
    Maybe I should describe what I am looking to accomplish. I want to create a display above a form that will list static details from other tables (i.e. when editing a user's phone number, which is in one table, you want the user to see the person's name, which is in another table, and the form is based upon the phone table) ...
    Just as I am thinking about it, I thought of an idea. I could put some specific code in the before displaying page plsql section to query the database and use htp to output the information for data not in the table the form is based upon. I will try this and see how it works. It would have been nice to have just created a field that is not editable and had a default value, but this should work as well.
    Let me know if you see any problem with this or if you have any better suggestions.
    Thanks for the fast response.

  • Deafaul Value using SQL query

    Hi
    I'm trying to make a default value using Computations;
    when I create computation,
    I select
    Computation item: PXX_TEST
    computation type: SQL query
    computation Point: I tried all
    Computation: select X FROM Y WHERE X= '1'
    This is the way to get Default Value ??
    I need to display the value when the page is open
    Thanks
    MM

    MM,
    You can use the default value attribute of the item to set a value if the item's source produces a null. A computation (before/after header) can work too, but it's possible that the item source and Source Used attribute (Always/Only) are interfering with your computation so you might want to try setting Source Used to 'Only...' if you have a computation setting the item.
    Scott

  • Set initial value using SQL

    Hi,
    How do I set the 'initial value' property of a default value using an SQL statement?
    Any help appreciated,
    Rob

    Hi Kevin,
    you are right. It is sometimes confusing for the users, but it is - as you said - like setting the initial value, of course you can do some more complexity there.
    One big problem is. If you want to set the initial values in a detail record of a master-detail relatioship depending on the master-record, you CAN'T use it. If you change the master record to a record which doesn't have a detail, the WHEN-CREATE-RECORD trigger fires before the master-record really changes. That means, the detail will be initialized with data from the old master-record (the one you were in, before changing the master record). Stupid thing.
    I never tried the WHEN-DATABASE-RECORD trigger, I even don't know how it works. I think I have to check what it is doing.
    Regards,
    Torsten

  • Defaulting DFF Segment Value using sql statement in SSHR gives error when using parameter

    Dear All,
    i am having an issue that i am making one segment in DFF (SEGMENT3) being defaulted by using sql statement
    Select MAX(SEGMENT7) FROM PER_ANALYSIS_CRITERIA cri, PER_PERSON_ANALYSES ana where cri.Analysis_Criteria_id = ana.ANALYSIS_CRITERIA_ID and ana.PERSON_ID = :ANALYSES.PERSON_ID
    The Above Select Statement is working fine on the PUI form and getting the Default value correctly but when opening the SSHR page that contain this DFF, it  gives me the below error.
    "No field listener is registered to resolve field ANALYSES.PERSON_ID referenced by the flexfield with application short name PER and name PEA. Please contact your system administrator. "
    Any Help Please???

    Please see the following docs.
    Cannot Add Salary:No Field Listener is Registered to Resolve Field Review.assignment_id (Doc ID 558295.1)
    No Field Listener Is Registered To Resolve Field Assgt.Effective_start_date (Doc ID 889794.1)
    List of Current Enhancement Requests (ER) for Oracle EBS Self Service Human Resource (SSHR) (Doc ID 1381936.1)
    No field listener is registered to resolve field xxx.xxx referenced by the flexfield with application short name ASO... (Doc ID 1359270.1)
    Customer Form, Address Error: No field listener is registered to resolve field GLOB.FLEX_COUNTRY_CODE referenced by the flexfield with application short name AR (Doc ID 1276934.1)
    DFF issue : No Field Listener Is Registered To Resolve Field XXX Referenced By The Flexfield (Doc ID 555589.1)
    Thanks,
    Hussein

  • Getting Top N Value using SQL

    There are thousands of records in a table. The table has column TOTAL_NUMBER. I want to find the top 3rd using the column TOTAL_NUMBER. How can I do this using SQL?

    Google:
    Using RANK() to Obtain a Top-N Query
    To obtain a top-N query, use RANK() in a subquery and then apply a filter condition outside the subquery:
    SELECT Empno, Ename, Job, Mgr, Hiredate, Sal
    FROM
    (SELECT Empno, Ename, Job, Mgr, Hiredate, Sal,
    RANK() OVER
    (ORDER BY SAL Desc NULLS LAST) AS Emp_Rank
    FROM Emp
    ORDER BY SAL Desc NULLS LAST)
    WHERE Emp_Rank < 6;

  • Avoid duplicate inserts using SQL statement?

    I have primary key on three columns and I want to write a sql statement to insert a row only if the matching three columns doesn't exist in the database.
    This is the condition I wrote but doesn't work. Could someone suggest me a query which meets this criteria.
    INSERT INTO JAVA_SERVICES (SERVICE_PAGE, SERVICE_TYPE, SERVICE_NAME,
      ROOT_PATH)
      VALUES ('AAAA', 'BBBB', 'CCCC', 'njdex') WHERE SERVICE_PAGE != 'AAAA' AND SERVICE_TYPE != 'BBBB' AND SERVICE_NAME != 'CCCC'Edited by: user626618 on Jun 12, 2009 2:39 PM

    you need to provide us more details such as what table name and column names are you using. using an insert into statement an example would be like:
    insert into java_services
    (service_page, service_type, service_name, root_path)
    select [column name], [column name], [column name]
      from [table name]
    where ([column name], [column name], [column name]) not in (select SERVICE_PAGE, SERVICE_TYPE, SERVICE_NAME
                                                                   from JAVA_SERVICES);
    begin
      for i in (select [column name] col1, [column name] col2, [column name] col3
                  from [table name]
                 where ([column name], [column name], [column name]) not in (select SERVICE_PAGE, SERVICE_TYPE, SERVICE_NAME
                                                                    from JAVA_SERVICES)) loop
        insert into java_services
          (service_page, service_type, service_name, root_path)
        values
          (i.col1, i.col2, i.col3);
      end loop;
    end;
    /

  • Viewing blob datatype value using sql query

    How can i view the text stored in a column of data type blob.
    Thanks.

    using pl/sql developer sql window i want to see the result.Is there any way of converting blob type to varchar type

  • How to read repeated tag values using sql query

    Database version
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    CORE 11.2.0.2.0 Production
    TNS for Linux: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production
    Question
    How to get repeated tag values?
    <TXLife>
    <TXLifeRequest>
    <TransRefGUID>10bc80e7d60e59b0:a134d0:10d7c4674ad:-7ffd</TransRefGUID>
    <TransType tc="1203">OLI_TRANS_TRNHLD</TransType>
    <TransExeDate>2011-02-27</TransExeDate>
    <TransExeTime>15:06:35</TransExeTime>
    <InquiryLevel tc="3">OLI_INQUIRY_OBJRELOBJ</InquiryLevel>
    <InquiryView>
    <InquiryViewCode>PLANUPDATE_CHBM_1203A</InquiryViewCode>
    </InquiryView>
    <OLifE>
    <SourceInfo>
    <SourceInfoName>CHBM Admin Tool</SourceInfoName>
    </SourceInfo>
    <Activity id="Activity1" HoldingID="Holding1">
    <UserCode>User123</UserCode>
    <LastUpdate>2011-02-27</LastUpdate>
    <ActivityCode>CHBM10001</ActivityCode>
    <OLifEExtension VendorCode="0098" ExtensionCode="Activity">
    <ActivityExtension>
    <SubActivityCode>CHBM20002</SubActivityCode>
    <LastUpdateTime>15:06:35</LastUpdateTime>
    </ActivityExtension>
    </OLifEExtension>
    </Activity>
    <Holding id="Holding1">
    <HoldingTypeCode tc="6">Group Master Contract</HoldingTypeCode>
    <Purpose tc="36">Business Protection and Preservation</Purpose>
    <Policy>
    <CarrierAdminSystem>CHBM</CarrierAdminSystem>
    <PolNumber>CHB0001234</PolNumber>
    <OLifEExtension VendorCode="0098" ExtensionCode="Policy">
    <PolicyExtension>
    <BillingDetail>
    <PaymentMode tc="3">Quarterly</PaymentMode>
    <BillingOrder tc="1009800002">Employee ID</BillingOrder>
    </BillingDetail>
    <SalaryAllotment>12354333</SalaryAllotment>
    </PolicyExtension>
    </OLifEExtension>
    </Policy>
    <Attachment id="Attach1">
    <DateCreated>2011-02-27</DateCreated>
    <UserCode>System</UserCode>
    <AttachmentBasicType tc="1">Text</AttachmentBasicType>
    <Description>Event 4</Description>
    <AttachmentData>Event Log</AttachmentData>
    <AttachmentType tc="1009800001">Transaction Log</AttachmentType>
    <AttachmentLocation tc="1">Inline</AttachmentLocation>
    <OLifEExtension VendorCode="0098" ExtensionCode="Attachment">
    <AttachmentExtension>
    <Sequence>2</Sequence>
    <CreationTime>16:05:45</CreationTime>
    </AttachmentExtension>
    </OLifEExtension>
    </Attachment>
    <Attachment id="Attach2">
    <DateCreated>2011-02-27</DateCreated>
    <UserCode>System</UserCode>
    <AttachmentBasicType tc="1">Text</AttachmentBasicType>
    <Description>Event 3</Description>
    <AttachmentData>Event Log</AttachmentData>
    <AttachmentType tc="1009800001">Transaction Log</AttachmentType>
    <AttachmentLocation tc="1">Inline</AttachmentLocation>
    <OLifEExtension VendorCode="0098" ExtensionCode="Attachment">
    <AttachmentExtension>
    <Sequence>1</Sequence>
    <CreationTime>16:01:54</CreationTime>
    </AttachmentExtension>
    </OLifEExtension>
    </Attachment>
    <Attachment id="Attach3">
    <DateCreated>2011-02-27</DateCreated>
    <UserCode>P62350</UserCode>
    <AttachmentBasicType tc="1">Text</AttachmentBasicType>
    <Description>Note 2</Description>
    <AttachmentData>Enter notes on changes or edits to plan</AttachmentData>
    <AttachmentType tc="14">Note</AttachmentType>
    <AttachmentLocation tc="1">Inline</AttachmentLocation>
    <OLifEExtension VendorCode="0098" ExtensionCode="Attachment">
    <AttachmentExtension>
    <Sequence>2</Sequence>
    <CreationTime>16:02:23</CreationTime>
    </AttachmentExtension>
    </OLifEExtension>
    </Attachment>
    </Holding>
    </OLifE>
    </TXLifeRequest>
    </TXLife>
    Expected output shoulb be like this
    Description AttachmentType AttachmentData
    Event 4 Transaction Log Event Log
    Event 3 Transaction Log Event Log
    Note 2 Note Enter notes on changes or edits to plan
    Please help me any one on this
    Edited by: LRAJESH on Apr 20, 2011 8:27 AM

    SELECT
    t2. Description des,
    t2.AttachmentType attty,
    t2.DateCreated DateCreated,
    t2.UserCode UserCode,
    t1.Planid Planid,
    t2.createdtime,
    t1.Ausercode Ausercode
    FROM (
    SELECT xData doc
    FROM dual
    ) temp_table,
    XMLTable ( '/TXLife/TXLifeRequest/OLifE' passing doc
    COLUMNS
    Planid varchar2(20) path 'Holding/Policy/PolNumber',
    AttachmentType xmltype path 'Holding//Attachment' ,
    Ausercode varchar2(20) path 'Activity/UserCode'
    ) t1,
    XMLTable
    '/Attachment'
    passing t1.AttachmentType
    columns
    Description varchar2(1000) path 'Description',
    AttachmentType varchar2(1000) path 'AttachmentType/@tc',
    DateCreated varchar2(20) path 'DateCreated',
    createdtime varchar2(20) path 'OLifEExtension/AttachmentExtension/CreationTime',
    UserCode varchar2(200) path 'UserCode'
    ) t2

  • Default Value using SQL

    Hi,
    How can I default a value in a descriptive flexfield by source of transaction? I am trying to update an invoice flexfield by source but it won't let me perform an update query as follows:
    update ra_customer_trx_all cac set attribute15 = 'Ready' where bac.batch_source_id = 1052
    Any ideas?

    This forum is not appropriate for DFF related query. Post this query in "Oracle Application" related forum.

  • Avoiding Duplicate Values Using LOV

    Hi
    I have the following code in WHEN_VALIDATE_ITEM trigger on a text item named REASON_ID.
    ------------------xxxxxxxxx--------------------------------
    DECLARE
    rg_id RecordGroup;
    rec_count NUMBER;
    BEGIN
    -- Get the record group ID --
    rg_id := Find_Group( 'REASONS_RG' );
    -- Get the number of rows --
    rec_Count := Get_Group_Row_Count( rg_id );
    -- delete the selected row --
    FOR j IN 1..rec_Count LOOP
    If Get_Group_Number_Cell( 'REASONS_RG.ID', j ) = :PREF_REASONS_TO_JOIN.REASON_ID Then
    Delete_Group_Row( rg_id, j );
    exit ;
    End if ;
    END LOOP;
    END;
    -------------------------xxxxxxxxxxxxxx----------------------
    Record Group REASONS_RG exists and contains ID in the SELECT statement.
    LOV REASONS_LOV is working fine as expected.
    Now When I click on this item REASONS_ID, LOV is displayed automatically and I select the record that I want. Then I press enter to change record and make another selection. This trigger should prevent me from selecting the same record twice (it should actually remove that record to be displayed in the LOV) right? But it doesn't work. I can still select the same record.
    Can anyone help me with this please?
    I got the above trigger code from this forum only and I guess many people have tried it and were able to restrict duplicates. I dont know what I am doing wrong here.
    Thanks in advance

    Hello,
    Yes, the automatic refresh must be set to NO, else, the record group is re-populated each time.
    Francois

  • Concatenate using SQL rather than Oracle functions Oracle 8i

    Is it possible to concatenate field values using SQL alone and not an Oracle function
    For the following dataset I would like the results to be the following
    1 User_lastname1 2,7
    2 User_lastname2 2,7
    3 User_lastname3 2
    4 User_lastname4 7
    CREATE TABLE users
    ( user_id NUMBER(10)
    , user_lastname VARCHAR2 (50)
    , workgroup NUMBER(10)
    INSERT ALL
    INTO users(user_id, user_lastname, workgroup) VALUES (1, User_lastname1, 2)
    INTO users(user_id, user_lastname, workgroup) VALUES (1, User_lastname1, 7)
    INTO users(user_id, user_lastname, workgroup) VALUES (2, User_lastname2, 2)
    INTO users(user_id, user_lastname, workgroup) VALUES (2, User_lastname2, 7)
    INTO users(user_id, user_lastname, workgroup) VALUES (3, User_lastname3, 2)
    INTO users(user_id, user_lastname, workgroup) VALUES (4, User_lastname4, 7)

    Maybe (provided a user is not a member of more than six workgroups)
    select user_id,
           user_lastname,
           max(decode(rno,1,workgroup,null)) || max(decode(rno,2,','||workgroup,null)) ||
                                                max(decode(rno,3,','||workgroup,null)) ||
                                                max(decode(rno,4,','||workgroup,null)) ||
                                                max(decode(rno,5,','||workgroup,null)) ||
                                                max(decode(rno,6,','||workgroup,null)) string
      from (select user_id,
                   user_lastname,
                   workgroup,
                   row_number() over (partition by user_id,user_lastname order by workgroup) rno
              from users
    group by user_id,
              user_lastname
    order by user_id,
              user_lastnameor (provided a user is not a member of more than five workgroups)
    select user_id,
           user_lastname,
           string
      from (select user_id,
                   user_lastname,
                   row_number() over (partition by user_id,user_lastname order by workgroup) rno,
                   workgroup || lead(','||workgroup,1) over (partition by user_id,user_lastname order by workgroup) ||
                                lead(','||workgroup,2) over (partition by user_id,user_lastname order by workgroup) ||
                                lead(','||workgroup,3) over (partition by user_id,user_lastname order by workgroup) ||
                                lead(','||workgroup,4) over (partition by user_id,user_lastname order by workgroup) string
              from users
    where rno = 1
    order by user_id,
              user_lastnameRegards
    Etbin

  • How to load a default value in to a column when using sql loader

    Im trying to load from a flat file using sql loader.
    for 1 column i need to update using a default value
    how to go about this?

    Hi!
    try this code --
    LOAD DATA
       INFILE 'sample.dat'
       REPLACE
       INTO TABLE emp
       empno   POSITION(01:04) INTEGER EXTERNAL NULLIF empno=BLANKS,
       ename   POSITION(06:15)  CHAR,
       job         POSITION(17:25)  CHAR,
       mgr       POSITION(27:30)  INTEGER EXTERNAL NULLIF mgr=BLANKS,
       sal        POSITION(32:39)  DECIMAL EXTERNAL NULLIF sal=BLANKS,
       comm   POSITION(41:48)  DECIMAL EXTERNAL DEFAULTIF comm = 100,
       deptno  POSITION(50:51)  INTEGER EXTERNAL NULLIF deptno=BLANKS,
       hiredate POSITION(52:62) CONSTANT SYSDATE
      )-hope this will solve ur purpose.
    Regards.
    Satyaki De.

  • Retreving Hexadecimal Values from a table using SQL query.

    Hi,
    I'm looking for a query to retreive Hexadecimal values contained in a column using SQL query.
    The column contains the values of all types, alphanumeric, numeric and hexadecimal.
    I need to retreive only hexadecimal values.
    any help to me in this regard will be appreciated.
    Thanks

    Presumably, you can be sure that any valid hex value is indeed MEANT to BE a hex value. For example the value 'ACE' is meant to be a hexadecimal value and not the word.

  • Assigning values to 2 fields using sql statement

    db11g , apex 4.0 and firefox 24 ,
    hi all ,
    i am trying to follow this tutorial to assign values to 2 items on a page using sql statement ,
    and i am using the same sql statement the tutorial uses
    select d.loc location, count(e.empno) num_employees from dept d, emp e where d.deptno = e.deptno(+) and d.deptno = :P3_DEPTNO group by d.loc -- btw , what does the "+" sign mean?
    after the e.deptno in the where condition .
    but i am facing this error
    1 error has occurred
    Wrong number of columns selected in the SQL query. See Help of attribute for details.
    and it does not work with two columns in the select statement under any conditions , i tried to remove the group function and the group clause ,
    it does not work unless i use only one column in the select statement ??
    thanks

    Pars
    And how exactly is this rewrite of the sql statement resolving the OP's issue.
    You are still using more than 1 column which will still result in the error message:
    Wrong number of columns selected in the SQL query.
    As mentioned in my earlier post APEX 4.0 (the version the OP is using) does not handle a sql statement with multiple columns for the dynamic action Set Value.
    Which means the fastest  and simplest solution is splitting up the dynamic action in multiple Set Value actions.
    Using this plugin or upgrade to a newer apex version would also be a possibility.
    Nicolette

Maybe you are looking for

  • How to Configure a oracle R12 with RAC on two different  system .

    I have one laptop and one desktop Laptop---- on laptop I have install vmware 8 Host OS --win7 Guest OS---linux 4 Desktop --- On Desktop I have install Vmware 8 Hosts OS --- Win XP Guest OS ---Linux 4 Plz suggest How configure oracle R12 with RAC usin

  • Need help in processing an excel into SAP

    Hi All.. Im uploading an excel file from presentation server to SAP... Now the problem is hw to know how many records are there in the excel file.. Have coded like below... w_max = '65536'.   w_counter_lo = '2'.    "Start on row 1 because of header r

  • How to backup my old iPhone 4 in tunes

    Hi, I just purchase new Iphone5S. now I need to backup all my old iphone 4 contact list and app to itunes, then copy to new iphone 5. Please let me know how to do it.

  • Problem with reCAPCHA plug-in

    hi, i m using Apex4.1 and data base oracle 11g, browser firefox i m using recaptcha plugins i had tried it with both way by creating 3 hidden field and and also directly with taking a item based on plugin. (http://www.inside-oracle-apex.com/adding-ca

  • Mac G5

    I bought a new MAC G5 in 2005. I had to replace the mother board last year and now after taking it in because the fan was blowing real loud, they tell me the logic board needs to be replaced. It is going to cost $899. Is this the same thing as the mo