Avoiding Duplicate Data Before Update syntax for a Table

Dear All,
CREATE TABLE TABLENAME
ID NUMBER,
COUNTRY VARCHAR2(10),
STATE VARCHAR2(10),
JOB VARCHAR2(10),
RNO VARCHAR2(10)
The rows looks like this
ID | COUNTRY | STATE | JOB | RNO
1 | India | Delhi | Abc | IndDel000001
2 | USA | NewYork | Def | USANew000001
3 | Japan | Tokyo | Ghi | JapTok000001
4 | India | Delhi | Abc | IndDel000002
5 | USA | LosAngeles | Def | USALos000001
6 | India | Delhi | Ghi | IndDel000003
The format goes this way to update RNO Field
select LPAD(NVL(MAX(CAST(SUBSTR(RNO,7) AS INT))+1,1),6,'0') AS INC_NO FROM TableName
where SUBSTR(RNO,1,3) = VAR_COUNTRY
AND SUBSTR(RNO,4,3) = VAR_STATE
SUPPOSE VAR_COUNTRY ='IND'
VAR_STATE ='DEL'
THE OUTPUT SHOULD BE INDDEL000004
UPDATE TABLENAME
SET RNO = VAR_COUNTRY || VAR_STATE || INC_NO
WHERE ID = IDNO;
COMMIT;
Records get inserted into this table from various users accross the world
The Higlighted field is RNo which is used during updation from different users at certian vaildation rules defined
During this time it is possible that 2 or more users get the same INC_NO
for a specfic VAR_COUNTRY and VAR_STATE
so what happens RNO fiellds get duplicated which should not be the case
The RNO field should bu unique
we cannot index the Field RNO since this field is empty while inserting records in TableName Table so the field is null and gets updated later at a certain stage
Plse help me
Best Regards
Edited by: user10996371 on Nov 2, 2009 8:49 PM

1) You are looking for serial numbers.
2) There is no other option than Sequences (To my knowledge :) )
You will have to do some ground work.
the ground work will be
1) Chalk out all the countries/states combination you have
2) create sequences for them
3) Create a function which will give you the next number for that combination
4) PLan to give corrrect privileges to users who will eb using this.
Below the code that i tested.
CREATE SEQUENCE ind_del INCREMENT BY 1;
CREATE SEQUENCE usa_new INCREMENT BY 1;
CREATE SEQUENCE jap_tok INCREMENT BY 1;
CREATE OR REPLACE FUNCTION nxt_num (cnt_name VARCHAR2,state_name VARCHAR2)
RETURN NUMBER IS
sql_stmt VARCHAR2(500);
next_num NUMBER(10);
BEGIN
EXECUTE IMMEDIATE 'select '||cnt_name||'_'||state_name||'.nextval from dual'INTO next_num;
RETURN next_num;
END nxt_num;
select '&cnt_name'||'&state_name'||lpad(nxt_num('&cnt_name','&state_name'),6,0) FROM dual;
You may have to benchmark it for performance
Cheers!!!
Bhushan
Edited by: Buga on Nov 3, 2009 10:47 AM

Similar Messages

  • Ensure List/Menu populate my update form with the correct data before update

    Hello,
    Please how do I ensure my update form is populated with the correct data before update?
    On my update page I have text fields and select fields (dynamic list/menu). When I open my profile page to make updates, I see the field well positioned in the text fields but in the select list/menu fields, I see "Select from list" instead of the value that was initiated selected
    Correct Values before update
    Wrong values during update
    As you can see from the images below, when I open the update page, the list automatically populate the select fields with the last values in the list instead of the Initial values that where selected by the user before the update.
    Can anyone please review and let me know where I have gone wrong.
    Thank you
    Mike

    Hello All,
    Once more thank you. I have sorted the issue out.
    I observed that I was selecting the wrong field. I selected the field matching the record set of the select instead of the field matching the record set of the table I am working as seen on the image belew
    I was selecting this - This is the record set of the table that hold values for the city select list
    Instead of this. This is the record set of the table behind the form I am working on
    My issue is now re-solved.
    Mike

  • How do i avoid duplicate data when synching iphone and mac book to the cloud?

    When I left my job for the last time I uploaded my Microsoft Outlook Contacts to the Cloud so that I could synch it with my Iphone (which I did).  Now I would like to also synch the Address Book on my Macbook  with the Cloud and my Iphone so I can integrated all of these contacts.  First I do not know if I can do this since my MACbook is a few years old aand I do not see the Cloud Icon anywhere on it.   Second of all I am not sure which area (Cloud, Iphone, or Macbook) take precedence when synching.   Can I lose data?  Does one systems dat over ride the other?  How can I avoid duplicate data?    I am a fairly new Mac user and  love the way things are integrated so I think I should not worry but I need help.  thanks, tdag55

    Hi meadowD,
    If you are looking to remove duplicate files from iTunes, you may find the following article useful (in the most recent versions of iTunes 11, the Display/Show Duplicate Items option has been moved to the View menu):
    Apple Support: How to find and remove duplicate items in your iTunes library
    http://support.apple.com/kb/ht2905
    Cheers,
    - Brenden

  • How to avoid duplicate posting of noted items for advance payment requests?

    How to avoid duplicate posting of noted items for advace payments request?

    Puttasiddappa,
    In the PS module, we allow the deletion of a component pruchase requisition allthough a purchase order exists. The system will send message CN707 "<i>A purchase order already exists for purchase requisition &</i>" as an Iinformation message by design to allow flexible project management.
    If you, however, desire the message CN707 to be of type E you have to
    modify the standard coding. Doing so, using SE91, you can invoke the
    where-used-list of message 707 in message class CN, and to change the
      i707(cn)
    to
      e707(cn)
    where desired.
    Also, user exit CNEX0039 provides the possibility to reject the
    deletion of a component according to customers needs e. g. you may
    check here whether a purchase order exists and reject the deletion.
    Hope this helps!
    Best regards
    Martina Modolell

  • Avoid Duplicate Tasks when Expanding Groups for Custom Task Process

    Is there a way to:
    Avoid Duplicate Tasks when Expanding Groups for Custom Task Process?
    I've got a people metadata column that I am planning on putting groups into.  I want the groups to expand and send a task for all users in the groups.  I also want to avoid creating multiple tasks if a user happens to be in two groups at the same
    time.
    I'm trying to work out a way to assign users a read task based on job training requirements.  Right now assigning groups and using a workflow task to confirm read is what I'm trying to accomplish.  I just end up getting two tasks for a user if
    their in multiple groups.
    David Jenkins

    Hi David,
    Please verify the followings:
    After Participants, select Parallel(all at a once)
    Expand Task Options, select ‘Assign a task to each member within groups’
    Open the action properties, make sure ExpandGroup is Yes
    Also in SharePoint Designer ,you can edit the property for the Start Approval Porcess to enable ExpandGroup:
    Reference:
    https://social.msdn.microsoft.com/Forums/office/en-US/d14da1c4-bd5a-459b-8698-3a89bb01e6ad/expand-groupnot-creating-tasks-for-users-issue-in-sharepoint-2013-designer-workflow?forum=sharepointgeneral
    https://social.technet.microsoft.com/Forums/office/en-US/ac245d45-ff66-4341-815c-79213efc4394/sharepoint-2010-designer-workflows-and-sharepoint-user-groups?forum=sharepointcustomizationprevious
    Best Regards,
    Eric
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • How to avoid duplicate data while inserting from sample.dat file to table

    Hi Guys,
    We have issue with duplicate data in flat file while loading data from sample.dat file to table. How to avoid duplicate data in control file.
    Can any one help me on this.
    Thanks in advance!
    Regards,
    LKR

    No, a control file will not remove duplicate data.
    You would be better to use an external table and then remove duplicate data using SQL as you query the data to insert it to your destination table.

  • HT1386 how to backup my apps and data before update to iOS5

    how to backup my apps and data before update to iOS5

    When you update, iTunes will backup your iOS device.  You can also do it manually... http://support.apple.com/kb/ht1766

  • Write the syntax for declaring table control in dialog programming?

    1) Write the syntax for declaring table control in dialog programming?
    2) Write the syntax to call a selection screen in a modal dialog box?

    hi,
    check this code for table control.
    DIALOG PROGRAMMING
    TABLE CONTROL
    IN SE51
    PROCESS BEFORE OUTPUT.
    MODULE STATUS_0100.
    LOOP AT ITVBAK WITH CONTROL TABCTRL. ##  TABLE CONTROL NAME
    ENDLOOP.
    PROCESS AFTER INPUT.
    MODULE USER_COMMAND_0100.
    LOOP AT ITVBAK.
    ENDLOOP.
    IN PAI FLOW LOGIC
    PROGRAM YMODULE_PR4 .
    TABLES : KNA1, VBAK.
    DATA : BEGIN OF ITVBAK OCCURS 0,
           VBELN LIKE VBAK-VBELN,
           ERDAT LIKE VBAK-ERDAT,
           ERNAM LIKE VBAK-ERNAM,
           NETWR LIKE VBAK-NETWR,
           END OF ITVBAK.
    CONTROLS : TABCTRL TYPE TABLEVIEW USING SCREEN '0100'.
    TO ACTIVATE SCROLL BAR
    *&      Module  USER_COMMAND_0100  INPUT
          text
    MODULE USER_COMMAND_0100 INPUT.
      CASE SY-UCOMM.
        WHEN 'EXIT'.
          LEAVE PROGRAM.
        WHEN SPACE.
          SELECT VBELN ERDAT ERNAM NETWR
            FROM VBAK
            INTO TABLE ITVBAK
           WHERE KUNNR = KNA1-KUNNR.
          TABCTRL-LINES = SY-DBCNT.
      ENDCASE.
    ENDMODULE.                 " USER_COMMAND_0100  INPUT
    *&      Module  STATUS_0100  OUTPUT
          text
    MODULE STATUS_0100 OUTPUT.
    SET PF-STATUS 'xxxxxxxx'.
    SET TITLEBAR 'xxx'.
    ENDMODULE.                 " STATUS_0100  OUTPUT

  • Updating model for pivot table in af:iterator

    Using Master Detail relationship, i am trying to create multiple forms at runtime. I want to show all the forms at once. Each form has some header fields and a pivot table. Header field is coming from master table and pivot table should be made from child.
    I am using af:iterator to iterate over master table rows and show header:
    <af:iterator id="i1"
                value="#{bindings.MasterTableVO.collectionModel}" var="row"
                varStatus="index"> For pivot table, i dragged Child View Object from Data Controls to make pivot table.
    <dvt:pivotTable id="pivotTable1"
              value="#{bindings.ChildTableVO.pivotTableModel}"
              summary="pivot table" sizing="auto"
              pivotEnabled="false" drillingEnabled="false"/>                                    Now while iterating, i am not able to get updated model for pivot table. Values from Master table are being updated, but pivot table from child table showing details corresponding to the first row of master table everywhere.
    So can you please help me, how to get the updated pivot table model corresponding to the current row in parent iterator ?
    I am using JDeveloper 11.1.1.6.0
    Thank You.
    VS

    Hi Aswini ,
    I didnot worked for me. I need to change the usecase a bit..
    however you can eaisly display the af:table inside iterator in readonly mode, but when you perform crud operations inline then it gives problems..
    Can you explain your usecase.
    Regards,
    Santosh.

  • How to get the data from pcl2 cluster for TCRT table.

    Hi frndz,
    How to get the data from pcl2 cluster for tcrt table for us payroll.
    Thanks in advance.
    Harisumanth.Ch

    PL take a look at the sample Program EXAMPLE_PNP_GET_PAYROLL in your system. There are numerous other ways to read payroll results.. Pl use the search forum option & you sure will get a lot of hits..
    ~Suresh

  • How to avoid duplicate data loading from SAP-r/3 to BI

    Hi !
           I have created one process chain that will load data into some ODS from R/3,where(in R/3)the datasources/tables r updated daily.
           I want to scheduled the system such that ,if on any day the source data is not updated (if the tables r as it is) then that data shuold not be loaded into ODS.
           Can any one suggest me such mechanism,so that I can always have unique data in my data targets.
           Pls ! Reply soon.
          Thank You !
           Pankaj K.

    Hello Pankaj,
    By setting the unique records option, you pretty much are letting the system know to not check the uniqueness of the records using the change log and the ODS active table log.
    Also, in order to avoid the problem where you are having dual requests which are getting activated at the same time. Please make sure you select the options "Set Quality Status to 'OK' Automatically" and "Activate Data Automatically" that way you would be having an option to delete a request as required without having to delete the whole data.
    This is all to avoid the issue where even the new request has to be deleted to delete the duplicate data.
    Untill and unless the timestamp field is available in the table on top of which you have created the datasource it would be difficult to check the delta load.
    Check the table used to make sure there is no timestamp field or any other numeric counter field which can be used for creating a delta queue for the datasource you are dealing with.
    Let me know if the information is helpful or if you need additional information regarding the same.
    Thanks
    Dharma.

  • Duplicate data records through DTP for attribute

    Hi Guys,
    I am loading data to customer master data, But it contains duplicate data in large volume.
    I have to load both attribute and text data .
    Data upto PSA level is correct, and text data also is loaded successfully.
    When i am loading attribute data to customer master ,it fails due to duplicate data records.
    Then in dtp with update tab, I select the check box for duplicate data records .
    As i select this check box ,at bottom it shows the
    message that *ENTER VALID VALUE* .
    After this message i am unable to click any function and repeat the same message again & again.
    So i am unable to execute the DTP.
    helpful answer will get full points.
    So please give me solution that the above mentioned message should not appear and then
    i will be able to Execute the data ?
    Thanks .
    Saurabh jain.

    Hi,
    if you get duplicate data for your customer there might be something wrong with your data source or the data in psa. But anyway, leave the dtp by restarting rsa1. Edit or create the dtp again and press save immediately after entering edit mode. Leave the dtp again and start editing it. That should do the trick.
    regards
    Siggi

  • How to avoid 'duplicate data record' error message when loading master data

    Dear Experts
    We have a custom extractor on table CSKS called ZCOSTCENTER_ATTR. The settings of this datasource are the same as the settings of 0COSTCENTER_ATTR. The problem is that when loading to BW it seems that validity (DATEFROM and DATETO) is not taken into account. If there is a cost center with several entries having different validity, I get this duplicate data record error. There is no error when loading 0COSTCENTER_ATTR.
    Enhancing 0COSTCENTER_ATTR to have one datasource instead of two is not an option.
    I know that you can set ignore duplicates in the infopackage, but that is not a nice solution. 0COSTCENTER_ATTR can run without this!
    Is there a trick you know to tell the system that the date fields are also part of the key??
    Thank you for your help
    Peter

    Alessandro - ZCOSTCENTER_ATTR is loading 0COSTCENTER, just like 0COSTCENTER_ATTR.
    Siggi - I don't have the error message described in the note.
    "There are duplicates of the data record 2 & with the key 'NO010000122077 &' for characteristic 0COSTCENTER &."
    In PSA the records are marked red with the same message (MSG no 191).
    As you see the key does not contain the date when the record is valid. How do I add it? How is it working for 0COSTCENTER_ATTR with the same records? Is it done on the R/3 or on the BW side?
    Thanks
    Peter

  • Update statement for object table.

    Hi,
    I have created one type as
    Create type test as object(
    ins_by varchar2(30),
    ins_on date,
    upd_by varchar2( 30),
    upd_on date);
    and then created an object table as
    create table imst(
    i_code number(5),
    i_desc varchar2(35),
    i_op test);
    now i am able to insert record in this table as
    insert into imst values(1,'Hawkins cooker',test(user,sysdate,'',''));
    Above works fine.
    But I would also like to update the record with i_op.upd_by,i_op.upd_on with some other values.
    Can any body help me specifying how to write a plain update statement for the same.
    Regards.
    Soumen

    Check it out:
    SQL> Create type myTest as object(
      2  ins_by varchar2(30),
      3  ins_on date,
      4  upd_by varchar2( 30),
      5  upd_on date);
      6  /
    Type created.
    SQL> create table imst(
      2  i_code number(5),
      3  i_desc varchar2(35),
      4  i_op myTest);
    Table created.
    SQL> insert into imst values(1,'Hawkins cooker', mytest(user,sysdate,'',''));
    1 row created.
    SQL> select * from imst;
        I_CODE I_DESC
    I_OP(INS_BY, INS_ON, UPD_BY, UPD_ON)
             1 Hawkins cooker
    MYTEST('APC_LOAD', '12-JUL-04', NULL, NULL)
    SQL> update imst i set i.i_op.upd_by = USER, i.i_op.upd_on = add_months(sysdate, 1);
    1 row updated.
    SQL> select * from imst;
        I_CODE I_DESC
    I_OP(INS_BY, INS_ON, UPD_BY, UPD_ON)
             1 Hawkins cooker
    MYTEST('APC_LOAD', '12-JUL-04', 'APC_LOAD', '12-AUG-04')
    SQL> Smoke me a kipper I'll be back before breakfast.
    Cheers, APC

  • HOw to improve insert/update/select  for nested table.

    Hi All,
    I think this is my second thread for nested table.
    i just want to know what are the different ways available to improve the insert/update/select operation on Nested table.
    Thanks in advance.

    By not using a nested table for data storage in the first place...
    http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:8135488196597
    Perhaps Parallel Query/DML might give some relief.

Maybe you are looking for