Edit existing or add new record based on key field

Greetings and Salutations!
I am working on an APEX 3.0 application and I need to verify a key field value to determine if the record already exists, if it does not exist, I need to add it, if it does exist, I need to update/edit it. I'm not sure how to do this, but below is what I am considering (in pseudo code):
get the asset_tag #
asset_search_value = :asv
select asset_tag from asset_table were asset_tag = :asv
IF :asv (unique key value is found) UPDATE
else
INSERT (create new record with asset_tag = :asv)
ENDIF
I hope that my explanation is clear.
I have considered doing a function to search for a key match and if one exists, I can proceed to the UPDATE screen, otherwise, I can proceed to that INSERT screen.
I'm intermediate with APEX and little better at pl/sql, but rapidly learning.
I should mention that my problem is coming up with a method to see if my query returns no records.
Thanks in advance for your assistance!
Charles
Message was edited by:
cp29020

Charles,
You said you were thinking about creating a function to search for a key match. First, I suggest you do so in a package. A function that returns a boolean should do. Something like what follows:
FUNCTION asset_exists (
   p_id IN TABLE_NAME.ID%TYPE
   RETURN BOOLEAN
AS
   l_retval BOOLEAN;
   CURSOR asset_exists_test_cur
   IS
      SELECT *
      FROM table_name
      WHERE id = asset_exists.p_id;
   l_asset_exists_test ASSET_EXISTS_TEST_CUR%ROWTYPE;  
BEGIN
   OPEN asset_exists_test_cur;
   FETCH asset_exists_test_cur INTO l_basic_user_test;
   l_retval := asset_exists_test_cur%FOUND;
   CLOSE asset_exists_test_cur;
   RETURN l_retval;
END asset_exists;Then you can use that function as needed to branch your logic. Remember to create a unique constraint on the table if it is not the primary key or doesn't already have one.
Dan

Similar Messages

  • To add new record into the table Data Service client

    When I am trying to add new record into the table Employeedetails using Data Service client it is giving a sql exception: "java.sql.SQLException: Violation of PRIMARY KEY constraint 'PK__EmployeeDetails__6383C8BA'. Cannot insert duplicate key in object 'EmployeeDetails'. Severity 14, State 1, Procedure 'PC-P41403 null', Line 1."
    Code:
    DataService ds=DataServiceFactory.newDataService(getInitialContext(),"EmplDetApp","ld:EmplDetAppDataServices/EmployeeDetails");
    EmployeeDetailsDocument edoc=EmployeeDetailsDocument.Factory.newInstance();
    edoc.addNewEmployeeDetails();
    //here I set the primary key value empid
    edet.setEmpid("1212");
    edet.setEmpname("manu");
    ds.submit(edoc);
    Error
    EmpName 5 java.sql.SQLException: Violation of PRIMARY KEY constraint 'PK__EmployeeDetails__6383C8BA'. Cannot insert duplicate key in object 'EmployeeDetails'. Severity 14, State 1, Procedure 'PC-P41403 null', Line 1
    com.bea.ld.dsmediator.DataServiceException: java.sql.SQLException: Violation of PRIMARY KEY constraint 'PK__EmployeeDetails__6383C8BA'. Cannot insert duplicate key in object 'EmployeeDetails'. Severity 14, State 1, Procedure 'PC-P41403 null', Line 1
         at com.bea.ld.dsmediator.update.JDBCAdaptor.save(JDBCAdaptor.java:247)
         at com.bea.ld.dsmediator.update.DataServiceMediator.submit(DataServiceMediator.java:528)
         at com.bea.ld.dsmediator.update.DataServiceMediator.submit(DataServiceMediator.java:245)
         at com.bea.ld.ServerBean.submit(ServerBean.java:529)
         at com.bea.ld.Server_ydm4ie_EOImpl.submit(Server_ydm4ie_EOImpl.java:910)
         at com.bea.ld.Server_ydm4ie_EOImpl_WLSkel.invoke(Unknown Source)
         at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:492)
         at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:108)
         at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:435)
         at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
         at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:147)
         at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:430)
         at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:35)
         at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224)
         at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183)
         at java.lang.Thread.startThreadFromVM(Unknown Source)
    Caused by: java.sql.SQLException: Violation of PRIMARY KEY constraint 'PK__EmployeeDetails__6383C8BA'. Cannot insert duplicate key in object 'EmployeeDetails'. Severity 14, State 1, Procedure 'PC-P41403 null', Line 1
         at weblogic.jdbc.mssqlserver4.TdsStatement.processWarning(TdsStatement.java:1178)
         at weblogic.jdbc.mssqlserver4.TdsStatement.parseMsWarning(TdsStatement.java:1089)
         at weblogic.jdbc.mssqlserver4.TdsStatement.getMoreResults(TdsStatement.java:756)
         at weblogic.jdbc.mssqlserver4.TdsStatement.execute(TdsStatement.java:210)
         at weblogic.jdbc.mssqlserver4.TdsStatement.executeUpdate(TdsStatement.java:97)
         at weblogic.jdbc.mssqlserver4.TdsStatement.executeUpdate(TdsStatement.java:1455)
         at weblogic.jdbc.wrapper.PreparedStatement.executeUpdate(PreparedStatement.java:147)
         at com.bea.ld.dsmediator.update.JDBCAdaptor.save(JDBCAdaptor.java:151)
         ... 15 more
    But I am not sure why it is giving an exception as Violation of PRIMARY KEY.
    The update method works fine for the same client.
    The exception only happens when I am trying to insert a new record.
    Please help me to figure out this problem.

    If you are absolutely sure that you do not have such a row already in your table, open a case with customer support and reference CR321312. I believe the work-around is to put ld-server-core.jar in your client classpath.
    Correction: put ld-server-app.jar in the client classpath
    Edited by mreiche at 09/17/2007 3:28 PM

  • Cannot find a way to edit bookmarks or add new folder as there is not a category edit bookmarks when I pull down the bookmark menu

    Updated to firefox 4.0 and can't find either the edit bookmarks or add new folder.

    I forgot that you are using a Mac. Please read this article:
    http://support.mozilla.com/en-US/kb/how-do-i-use-bookmarks#w_working-with-your-bookmarks-in-the-library-window
    Right click on "Bookmark Menu" and you should see a "New Folder" option.
    http://support.mozilla.com/en-US/kb/Bookmark%20folders#w_making-new-folders

  • Web GUI new feature - creating a new record based on the current record

    Vincent,
    We need new feature in Web GUI:
    creating a new record based on the current record with data
    from Moscow with money

    It is already enabled, in the next release.
    If you joint TAB program, the march preview build contains it. User can select 1 or multiple users and make a copy.

  • How do I add a record's primary key to a query string and add that to an .xml catalog?

    Hello everyone,
    I am using Dreamweaver CS3 on a MacBook Pro Leopard 10.5.6 and MAMP 1.7. I am also teaching myself how to work with PHP and MySQL, using David Powers book The Essential Guide to Dreamweaver CS3.
    I am trying to create a wedding photography web site, with a personal page after login, which will display the photographs of the customers wedding.
    The same page will also be a catalog/shopping cart, so the customer can choose which photo's they want, and pay for them. (I am aware that there are instructions in The Essential Guide in chapter 15 page 515, on how to redirect to a personal page, but it doesn't fully cover what I am asking).
    I have already created the login success page, which greets users by name, as per the instructions in The Essential Guide. I have also created a catalog page. However my catalog page is not calling information from the database, instead it is taking information from an XML page using PHP.
    I would like to insert a list menu on the login success page, which lists the customers name, and when they select their name they will then select a link that will take them to a personal page with just their wedding photographs.
    I am unsure of how to pass the customer_id, in what will be the username list menu, to the page which will contain the customers set of wedding images.
    Is it the same process used in chapter 14 where you add a record's primary key to a query string?
    I am asking because when I set up a recordset from the MySQL database it lists the images as witten names not actual images, I have tried calling the images with PHP code but it just doesn't work.
    The catalog page I have set up at the moment is not calling the images from the database, but directly from the image folder.
    Is what I am trying to do possible?
    If so how do I pass the customer_id and username to a recordset and link that recordset to the xml catalog so the customers personal wedding images are displayed on the catalog page for the shopping cart?  I need step by step instructions, or maybe a link to a good tutorial.
    Can somebody help me please?
    Thankyou.

    QuickTime 7 can set the poster frame, but I've not had much success with it. This is what QuickTime 7 Help says about this topic:
    +A "poster frame" is a still image of a movie that represents the movie in places like the Finder. The default poster frame is the first frame in the movie. You can change the poster frame.+
    +To change a movie's poster frame:+
    +In QuickTime Player 7, drag the playhead (or use the arrow keys to move the playhead) to the desired frame.+
    +Choose View > Set Poster Frame.+
    +To view a movie's poster frame, choose View > "Go to Poster Frame."+
    If you don't have QuickTime 7 (version 7.6.6) it can be installed from your Snow Leopard disc using a custom install. Otherwise download it from this Apple site: http://support.apple.com/kb/DL923
    John

  • Cannot add new records through VC form when consuming IP write back query

    I have created a planning application in IP and created a Form in VC (CE 7.1). I am not able to create new records in VC Form and save it back to the cube like the traditional excel form on IP does. I have attached a document with every step that i did as a screen shot in designing my model. The writing back of data using the Form works if i have preexisting data in the planning cube and if i am only changing the values of the existing data records it works great. I could consume the planning functions that i created and they work well within VC. But if i want to create new records in a empty planning cube it gives me error unlike planning in excel analyser lets me save it back to the cube. I have tested the same query in Excel Analyser and created new records and saved it back in the cube. Any help on this is greatly appreciated.
    [http://www.mediafire.com/?sharekey=f1bc9aa662da6a86d956df2962098fcbe04e75f6e8ebb871]
    Thanks.
    Edited by: BI GUYS on Sep 28, 2009 2:00 PM

    Hi PradeeP,
    1. The BI Query itself has to support the entries of new lines. This is described in note 1149346.
    However, if the Query allows entering new lines in the BEx Analyzer, then this prerequisite is fulfilled.
    2. In the BI Query wizard in VC in the u201CChoose Presentationsu201D step, you have to include  the key presentation for the characteristics.
    If 1 and 2 are fulfilled and you still have the problem, it is strange...
    Does the problem also occur if you create new records in a cube that already shows some data in the table view?
    Regards,
    Talia

  • BC4J tag - add new record only in child table using join query

    Hi,
    I have developed the struts base jsp for BC4J component application using jdeveloper wizard.
    i have first developed the BC4J component. using emp table and dept table,
    also developed the association between emp and dept , and create view object using created association.
    when i haae developed the the struts base jsp for BC4J applicaion using alerady created view object. it creates automatically DataEditComponent.jsp and DataTableComponent.jsp and etc...
    and when i want to add new row or record it automatically add the entry in both table ,
    in above scenario i have used dept as master and emp as child table.
    what is the solution , if i want to add row or record in only emp table.
    please help me

    Hi Reetesh,
    I have written following code into the ADD ROW button
    System.out.println("Coming in Click Event");
    OAApplicationModuleImpl am = (OAApplicationModuleImpl) pageContext.getApplicationModule(webBean);
    OAWebBean innerTablebean = (OAWebBean)webBean.findChildRecursive("region12");
    OATableBean innerTable = (OATableBean)webBean.findChildRecursive("innerTablebean");
    OAInnerDataObjectEnumerator enum = new OAInnerDataObjectEnumerator(pageContext,innerTablebean);
    while(enum.hasMoreElements())
    RowSet innerRowSet = (RowSet) enum.nextElement();
    Row []rowsInRange = innerRowSet.getAllRowsInRange();
    OARow newRow = (OARow) innerRowSet.createRow();
    OADBTransaction dbt = am.getOADBTransaction();
    Number b = dbt.getSequenceValue("PK_XX_BATCH_PROGRAM_PARAMETERS");
    newRow.setAttribute("ProgramId", b);
    newRow.setAttribute("ProgramParmId",b);
    newRow.setAttribute("ParameterName",new String(""));
    newRow.setAttribute("ParameterDataType",new String(""));
    newRow.setAttribute("ParameterInOutType",new String(""));
    innerRowSet.insertRow(newRow);
    Now the problem occurs only when there are more than one rows in parent table... As many rows are there in parent table that many times the rows are being added.
    With Regards,
    Sandip

  • Not Refresh Value After Add New Record used with RPC Component

    This is my code in the class Users.as
    package inthanous
    import mx.controls.Alert;
    import mx.rpc.http.HTTPService;
    import mx.rpc.events.ResultEvent;
    import mx.rpc.events.FaultEvent;
    public class Users
    private var service:HTTPService;
    [Bindable]
    public var xmllist_user:XMLList;
    public function Users(){
    service = new HTTPService();
    service.method = "POST";
    service.useProxy = false
    service.resultFormat = "e4x";
    public function listUser():void{
    service.url = "/user/get_all_user_group_name";
    service.addEventListener("result", httpResultListUser);
    service.addEventListener("fault", httpFaultListUser);
    xmllist_user = new XMLList();
    service.send();
    private function httpResultListUser(event:ResultEvent):void{
    service.removeEventListener("result", httpResultListUser);
    service.removeEventListener("fault", httpFaultListUser);
    xmllist_user = new XMLList(service.lastResult.children());
    listAllUser();
    private function httpFaultListUser(event:FaultEvent):void{
    var faulstring:String = event.fault.message;
    service.removeEventListener("result", httpResultListUser);
    service.removeEventListener("fault", httpFaultListUser);
    Alert.show(faulstring,"Error");
    public function createUser(_xml:XML):void{
    service.url = "/user/create_user";
    service.addEventListener("result", httpResultCreateUser);
    service.addEventListener("fault", httpFaultCreateUser);
    service.send({firstName: _xml.firstName,
    lastName: _xml.lastName,
    gender: _xml.gender,
    login: _xml.login,
    pwd: _xml.pwd,
    dtBirth: _xml.dtBirth,
    telephone: _xml.telephone,
    idGroup: _xml.idGroup
    private function
    httpResultCreateUser(event:ResultEvent):void{
    service.removeEventListener("result", httpResultCreateUser);
    service.removeEventListener("fault", httpFaultCreateUser);
    listUser();
    clearUserDetail();
    private function httpFaultCreateUser(event:FaultEvent):void{
    var faulstring:String = event.fault.message;
    service.removeEventListener("result", httpResultCreateUser);
    service.removeEventListener("fault", httpFaultCreateUser);
    Alert.show(faulstring,"Error");
    This code i used with Ruby on Rail to connect with MySQL.
    When i used with FireFox browse after i create new user
    success it refresh the new record in Datagrid. But for the Internet
    Explorer Datagrid not refresh it because of it display the old
    recode before create.
    So i don't know it problem by Internet Explorer or my script.
    i hope someone can help me the solve this problem.
    thanks

    If you restrict the selection, a record value outside of that selection is not acceptable and will give you this error. This is how BPS works.
    You need to restrict on some other char so BASIC1 doesn't come in, but this value should be part of any selection on ZSEGMENT field for it to be accepted back.

  • How to add new records in Start routine or end routine.

    Hi All,
            My requirement is to transfer data from one DSO to anothe DSO. But while transfering a single record frorm DSO1 i want to add 7 records to DSO2 for each record in DSO1 with slight change in data( with a different key). I want to do it in start routine or end routine. How can i do it. If you have any ABAP code for this then please send.
    Regards
    Amlan

    you can use this code, replace the fields where i have marked with <>.
    DATA : WA_RESULT_PACKAGE TYPE DSO2,
           WA_RESULT_PACKAGE1 LIKE WA_RESULT_PACKAGE.
    DATA : IT_RESULT_PACKAGE LIKE TABLE OF WA_RESULT_PACKAGE.
    DATA : DATE1 TYPE SY-DATUM.
    DATA : DAYDIFF TYPE i.
    DATA : RECORD_NO type rsarecord.
    SORT RESULT_PACKAGE BY <KEY FIELDS> "specify the key fields here
    RECORD_NO = 1.
    LOOP AT RESULT_PACKAGE INTO WA_RESULT_PACKAGE.
         IF WA_RESULT_PACKAGE_1-<KEYFIELDS> NE WA_RESULT_PACKAGE-<KEYFIELDS>.
              WA_RESULT_PACKAGE_1 = WA_RESULT_PACKAGE.
              DAYDIFF = WA_RESULT_PACKAGE-ENDDATE - WA_RESULT_PACKAGE-STARTDATE.
                   WHILE DAYDIFF NE 0.
                        DATE1 = WA_RESULT_PACKAGE-STARTDATE + DAYDIFF.
                        MOVE DATE1 TO WA_RESULT_PACKAGE-<KEYFIELDDATE>.
                        MOVE RECORD_NO TO WA_RESULT_PACKAGE-RECORD.
                        APPEND WA_RESULT_PACKAGE INTO IT_RESULT_PACKAGE.
                        DAYDIFF = DAYDIFF - 1.
                        RECORD_NO = RECORD_NO + 1.
                        CLEAR DATE1.
                   ENDWHILE.
              CLEAR DAYDIFF.
         ENDIF.
    ENDLOOP.
    DELETE RESULT_PACKAGE[].
    RESULT_PACKAGE[] = IT_RESULT_PACKAGE[].
    Reg Point 3.
    The Key figures will then show up in the report aggregated.Hope that is fine with you.
    Note:
    Before loading data, in DTP set the semantic key with the key field of the DSO1.This brings all the similar data w.r.t the key fields from the PSA together in a single package.
    rgds, Ghuru

  • JSF: how to add new record in datatable from same page

    Jdeveloper : 11.1.2.2.0
    using ADF i want to create a page that contains a datatable, input text field and a command button.
    when i press the command button i want the text in the input text field to be inserted as a new record in datatable.
    what is the best practice for that ? how to get the value of the input text field and insert it?
    thanks in advance :)

    thanks so much that really helped :)
    the solution is to do it programatically in a managed bean :)

  • Sorting issue on - around 20 records based on one field Data Manager

    Hello Experts,
    We are facing issue sorting some records which belong to one contract.
    if we sort by one field ie item no, it is not sorting based on this field. This issue only one set of contract only.
    For other set of data, sorting is working fine.
    Any hint will be appreciated.
    Thanks in advance

    HI saptest,
    I have not heard of such a issue,please provide detailed description of the same to give a better idea.
    Thanks,
    Ravi

  • Selecting records based on different fields

    Post Author: timg
    CA Forum: General
    I have three groups which I study quite often, the blues (as identified in field 1with codes), the reds (identified in field 2 with codes), and the greens (identified in field 3 with certain codes).
    I want to be able to run one report which, through a parameter field, I can select the group (red, green, or blue) for which I can select records from the database and analyze. Stated another way, if I select "Blue" in the parameter field, how can I get CR to pull certain records in the correct field with the correct codes.

    Post Author: yangster
    CA Forum: General
    dunno what your codes are but something like this will work if you put it in the section expertif ?para = "BLUE" then field1 in &#91;a, b, c&#93; elseif ?para = "RED" then field2 in &#91;d, e, f&#93; elseif ?para = "GREEN" then field3 in &#91;g, h, i&#93; 

  • To create multiple files on the receiver side based on key field

    Hi Gurus,
    My scenario is File to File
    My Source structure is as below
    My File looks like
    My file looks like below
    570774          11/26/2008 8:12     6296     xxxxxxx     985-399-5157     1153 Teche Road     Morgan City     United States     Lori Eisenman     Louisiana     70380     0          1153 Teche Road     Morgan City     United States     Lori Eisenman     Louisiana     70380     303     101400100000     3365440332522     ELLE YVES SAINT LAURENT Eau de Parfum Spray          2                    61     78     156     184     184     0
    570774          11/26/2008 8:12     6296     xxxxxxx     985-399-5157     1153 Teche Road     Morgan City     United States     Lori Eisenman     Louisiana     70380               1153 Teche Road     Morgan City     United States     Lori Eisenman     Louisiana     70380     376     106074700JP0     3365440347229     GOLDEN GLOSS N° 27Shimmering Lip Gloss          1                    28     28     28               0
    570775          11/26/2008 8:15     6296     xxxxxxx     985-399-5157     1153 Teche Road     Morgan City     United States     Lori Eisenman     Louisiana     70380     7          1153 Teche Road     Morgan City     United States     Lori Eisenman     Louisiana     70380     284     9000400000     3365440316546     L'HOMME  Eau de Toilette Spray          1                    53     53     53     60     60     0
    for each new order number(key field ex: 570774) a new xml file to be created , from the above example 2 xml files sholud be created(one for 570774 and the other for 570775)
    How can i acheive this functionality?
    Please help me on this, Thanks in advance
    Regards
    Srinivas

    Hi Srinivas,
                   map the key field to the parent record of the target field. Use the split by value and change the source key field level to higher one so that the all occurences of the key field are occuring. The mapping will be like this;
    Source Key Field (change to higher level) --> Spli by value --> Filename creation UDF --> Target header field.
    Try this.
    Regards,
    Murugavel.

  • Help: Using stored procedure to add new record in DB

    I am using stored procedures for a form. In DB, I have select and update procedures work without problems. However, for the insert procedure, it does not seem work right. Here is how things work for the insert procedure:
    1. On the form, I have an add record button, when this button is pressed, it calls the trigger "KEY_CREREC" with "create_record."
    2. A blank record is then shown on form. I then put in some test date. Apparently, this will cause "SYSTEM.STATUS" set to "CHANGED." when calling for commit, it only calls the DB update procedure.
    My question is how to make it call the insert procedure.
    Any suggestions are greatly appreciated.

    I just added to lines in key_commit to check the system.form_status:
    set_alert_property('AL_STOP', alert_message_text,'System Status: '||:system.form_status);
    al_button := show_alert('AL_STOP');
    After do_key('create_record') and some changes in fields, the :system.form_status shows "CHANGED.'
    Just wondering what will make the auto generated insert_procedure for the block to trigger. So far, no problems to do query and update with the DB stored procedure, but the insert does not seem working.
    Any help is greatly appreciated.
    P.S. The new post might be more clear:
    http://forums.oracle.com/forums/thread.jspa?threadID=675578&tstart=0
    Message was edited by:
    WJH

  • Creation of a new record based on the value of a picklist

    Hi,
    My requirement is whenever i select a picklist value in Opportunity record type based on the value selected a new opprtunity record should get created and get assigned to a role or A User otherwise a lead should get created and should be assigned to a Role or A User.
    Can I achieve this in OnDemand?
    Kindly help. This is urgent..
    Thanks in Advance.

    Can I achieve this in OnDemand?I think you can better try one of the Oracle CRM On Demand forums @ http://forums.oracle.com/forums/category.jspa?categoryID=162
    instead of the Oracle SQL and PL/SQL forum.
    This is urgent..The forums are relying on volunteers and it is weekend for most of us now.
    If it is really that urgent, call Oracle Support.

Maybe you are looking for

  • Possible to make pacman less verbose?

    Hi, During updates your sometimes see pacman print a whole list of signed keys that it has been updated, even those that have not changed. Would it be possible to remove this output? I do like package signing but I prefer not to be bothered with it a

  • How to valiadate on the basis of employee id selected...

    Hi All, My requirement is to use the validation on the basis of the employee id selected. My CO if (pageContext.getParameter("submitButton")!=null) OAViewObject vo = (OAViewObject)am.findViewObject("EmployeeEOVO1"); if (vo != null) System.out.println

  • Integration of JSR-168 portlet into Portal - Complete Guide

    Hi there, the CE 7.1 is described to be compatible with JSR-168 portlets. Our Company has developed a JSR-168 portlet which comes as a WAR-File which can be easily included in other application server and portals (WebShpere, Apache). But integration

  • Calling applets in jsp

    Hi All, When I tried to call an applet in my JSP page ,it says like " java plugin not installed properly"...I don't know what is wrong with my installation.I'm using jswdk server. Could anyone help me please.... Would Appreciate if I get help. Subha.

  • Will the indexes be ignored when using IMPDP...TABLE_EXISTS_ACTION=SKIP?

    Hi guys, 11gr2 suppose that i have a .dmp file which has tables, indexes, and data, and i also have a schema A which already contains tables and data, without indexes is it possible to use IMPDP to import(or say create) all indexes from .dmp to schem