Oracle - mettre à jour ou insérer
Solved
camilla
-
camilla -
camilla -
Hello,
from Oracle SQL Developer, I want to insert a row into a table if it does not exist; otherwise, I just want to update the row. Here is the query I used:
UPDATE TABLE SET ATTRIBUT1= 'value', ATTRIBUT2 = 'value', ATTRIBUT3 = 'value'
WHERE IDTABLE = 'value'
IF SQL%ROWCOUNT=0 INSERT INTO TABLE (IDTABLE, ATTRIBUT1, ATTRIBUT2, ATTRIBUT3)
VALUES ('value', 'value', 'value', 'value')
When I execute this query, it gives me an error: Unknown command
Configuration: Windows 7 / Firefox 11.0
from Oracle SQL Developer, I want to insert a row into a table if it does not exist; otherwise, I just want to update the row. Here is the query I used:
UPDATE TABLE SET ATTRIBUT1= 'value', ATTRIBUT2 = 'value', ATTRIBUT3 = 'value'
WHERE IDTABLE = 'value'
IF SQL%ROWCOUNT=0 INSERT INTO TABLE (IDTABLE, ATTRIBUT1, ATTRIBUT2, ATTRIBUT3)
VALUES ('value', 'value', 'value', 'value')
When I execute this query, it gives me an error: Unknown command
Configuration: Windows 7 / Firefox 11.0
4 réponses
Hello Heremion,
Thank you for getting back to me. Indeed, I tried with this syntax but I have two errors: invalid table name and the other command is unknown!!
Here I corrected my query after your response and here is exactly what I wrote:
UPDATE TABLE PERSONNE SET NOM= 'nom', PRENOM= 'prenom' WHERE IDPERSONNE= '01'
IF SQL%ROWCOUNT = 0 THEN INSERT INTO TABLE PERSONNE VALUES ('01', 'nom', 'prenom');
Thank you for getting back to me. Indeed, I tried with this syntax but I have two errors: invalid table name and the other command is unknown!!
Here I corrected my query after your response and here is exactly what I wrote:
UPDATE TABLE PERSONNE SET NOM= 'nom', PRENOM= 'prenom' WHERE IDPERSONNE= '01'
IF SQL%ROWCOUNT = 0 THEN INSERT INTO TABLE PERSONNE VALUES ('01', 'nom', 'prenom');