Insert if exists
Posted by: Macamba .
Date: January 03, 2016 07:50AM

I'm trying to test my Java application. To accomplish this I run a script that should insert a test account in the database, if it not exists. If it exists, I want it to update fields (to the first values).

I tried it with:
INSERT INTO address 
 (perident, street, number, pcode, city, telephone, email, eori, iban )
(!) VALUES 
 ('jdoe', 'Fill in your own address information', NULL, NULL, NULL, NULL, NULL, NULL, NULL)
 ON DUPLICATE KEY UPDATE 
 	perident = 'jdoe', street = 'Fill in your own address information', number = NULL, pcode = NULL, city = NULL, 
 	telephone = NULL, email = NULL, eori = NULL, iban = NULL);

I get the error
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 2 (at the '(!) ')

Options: ReplyQuote


Subject
Written By
Posted
Insert if exists
January 03, 2016 07:50AM
January 03, 2016 12:46PM
January 04, 2016 03:29AM
January 04, 2016 03:52AM
January 04, 2016 04:39AM
January 18, 2016 05:44PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.