How can we check that the data already exist in the database

Hi friends

I'm trying to create a procedure for adding clients in the database with the customer id as input parameter... but if the customer details database already exists that I would update this detail and is not in the database I want to add this detail in the database... How could I do that...

any help would be appreciated

Thank you
Rommy

Hello

If your condition is to add to a table, and if the record exists in the other table, the merge statement does not work

Example (Please check the column name and the parameter names). I do not commit or rollback because I do not know if you control the transaction within this procedure or outside it.

CREATE OR REPLACE PROCEDURE add_cust(I_CUST_ID        IN VARCHAR2,
                                     I_CUST_F_NAME    IN VARCHAR2,
                                     I_CUST_L_NAME    IN VARCHAR2,
                                     I_CUST_ADD       IN VARCHAR2,
                                     I_CUST_CITY      IN VARCHAR2,
                                     I_CUST_STATE     IN VARCHAR2,
                                     I_CUST_ZIP       IN VARCHAR2,
                                     I_CUST_DOB       IN DATE,
                                     I_CUST_          IN VARCHAR2,
                                     I_CUST_ACCT_TYPE IN VARCHAR2,
                                     I_START_BAL      IN NUMBER) IS
BEGIN
   INSERT INTO CUSTOMERS C
      (CUST_ID,
       CUST_F_NAME,
       CUST_L_NAME,
       CUST_ADD,
       CUST_CITY,
       CUST_STATE,
       CUST_ZIP,
       CUST_DOB,
       CUST_)
   VALUES
      (I_CUST_ID,
       I_CUST_F_NAME,
       I_CUST_L_NAME,
       I_CUST_ADD,
       I_CUST_CITY,
       I_CUST_STATE,
       I_CUST_ZIP,
       I_CUST_DOB,
       I_CUST_);

EXCEPTION
   WHEN DUP_VAL_ON_INDEX THEN
      INSERT INTO CUSTOMER_ACCT
         (CUST_ID,
          CUST_ACCT_NO,
          cust_acct_type)
      VALUES
         (I_CUST_ID,
          CUST_ACCT_SEQ.NEXTVAL, -- CUST_ACCT_SEQ is a sequence, isn't?
          I_CUST_ACCT_TYPE);

END add_cust;

Kind regards

Tags: Database

Similar Questions

Maybe you are looking for

  • Return to iTunes earlier?

    The new iTunes is an absolute stupidity. I've been using itunes for nearly a decade and the new GUI is absolute garbage. I tried to sync my music and it deleted my tones. Then synchronize my ringtones and it deleted my music and my shades removed fro

  • Satellite A40-SP151: can not make ethernet work card

    Hello I went and stupidly installed new XP on my Satellite A40 and I can't do the ethernet card working (just Windows will not recognize it).I tried MANY solutions (even some of this site) and the drivers and the problem is still there. If someone co

  • 2007 MacBook Pro gel

    Hello It is a recurring problem, even after dry and re - install, can someone shed light on this, the MBP dies? Yosemite, tried running Reset the PRAM and NVRAM on your Mac. MacIntel: Reset of the controller (SMC) system management same problem occur

  • Two monitors will not show extended display

    I just bought a HP Envy 7000 with two dell monitors. In addition, I bought a DVI - D splitter and two monitor DVI - D cables to connect the monitors. The two monitors work, but he won't show a mirrored display.  It is the splitter I bought for connec

  • BIOS update failed on the Satellite A100 - SK4 - how can I fix it

    I tried to update my bios but something went wrongduring the process and now the laptop does not start.(when I try to activate the satellite, nothing happens) Is there an easy way to simply delete it?When you turn it on, the screen is all black. The