Is there a non database-specific command for "insert or update"

Marc Stroebel

we use different databases for test (mysql) and production (oracle) systems. Is there a common sql statement for updating a row if it exists and insert if not?

Regards, Marc

Rahul Tripathi

The answer is NO. For MYSQL it will be different and for Oracle it will be different.

In MYSQL it would be like

INSERT INTO tabelname (id, name) 
VALUES (1, 'abc') 
ON DUPLICATE KEY UPDATE id = id;

In Oracle it would be like

DECLARE
    x NUMBER:=0;
BEGIN
    SELECT nvl((SELECT 1 FROM tabelname WHERE name = 'abc'), 0) INTO x FROM dual;

    IF (x = 1) THEN
        INSERT INTO tabelname (1,'abc')
    END IF;

END;

or you can use merge like this:

merge into tablename a
    using (select 1 id, 'abc' name from dual) b
        on (a.name = b.name)
    when not matched then
   insert( id, name)
      values( b.id, b.name)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Insert and update database remotely?

From Dev

Insert and update a datetime into SQL database

From Dev

Insert and update database with php mysql

From Dev

why command update in " insert or update " are working not right?

From Dev

why command update in " insert or update " are working not right?

From Dev

How to insert and Update simultaneously to PostgreSQL with sqoop command

From Dev

Can't insert or update record to database jsp

From Dev

Insert and Update data to database at the same time

From Dev

Insert and update from table in tmp database to table in another database

From Dev

Insert and update from table in tmp database to table in another database

From Dev

how to insert/update multiple rows into database without firing insert/ update query multiple times?

From Dev

How to use insert and update command using c#

From Dev

database triggers to populate current date on row insert and update not working

From Dev

Digitally signing an SQL Server database record or an insert/update operation

From Dev

one sql trigger insert,update,delete for all tables in the database

From Dev

Django "emulate" database trigger behavior on bulk insert/update/delete

From Dev

one sql trigger insert,update,delete for all tables in the database

From Dev

Select works in Sqlite Database but Insert and Update statements do not

From Dev

Connection class to MySQL database using PHP, insert , update, delete

From Dev

What command for showing disk usage of specific directory non recursive?

From Dev

What command for showing disk usage of specific directory non recursive?

From Dev

Allow non-root users to execute specific command

From Dev

How to INSERT OR UPDATE while MATCHING a non Primary Key without updating existing Primary Key?

From Dev

How to INSERT OR UPDATE while MATCHING a non Primary Key without updating existing Primary Key?

From Dev

How to compose proper insert/update/delete commands to update linked tables in source access database?

From Dev

How to insert, update and delete items from JTable that is loaded from (SQLite) Database

From Dev

Insert,update and delete data from Sql database using vb.net?

From Dev

Edit SQL Server Database (INSERT, UPDATE, etc) in ASP.NET (VB)

From Dev

How are store/website-specific (or non-global) products attributes stored/queried in the Magento mysql database?

Related Related

  1. 1

    Insert and update database remotely?

  2. 2

    Insert and update a datetime into SQL database

  3. 3

    Insert and update database with php mysql

  4. 4

    why command update in " insert or update " are working not right?

  5. 5

    why command update in " insert or update " are working not right?

  6. 6

    How to insert and Update simultaneously to PostgreSQL with sqoop command

  7. 7

    Can't insert or update record to database jsp

  8. 8

    Insert and Update data to database at the same time

  9. 9

    Insert and update from table in tmp database to table in another database

  10. 10

    Insert and update from table in tmp database to table in another database

  11. 11

    how to insert/update multiple rows into database without firing insert/ update query multiple times?

  12. 12

    How to use insert and update command using c#

  13. 13

    database triggers to populate current date on row insert and update not working

  14. 14

    Digitally signing an SQL Server database record or an insert/update operation

  15. 15

    one sql trigger insert,update,delete for all tables in the database

  16. 16

    Django "emulate" database trigger behavior on bulk insert/update/delete

  17. 17

    one sql trigger insert,update,delete for all tables in the database

  18. 18

    Select works in Sqlite Database but Insert and Update statements do not

  19. 19

    Connection class to MySQL database using PHP, insert , update, delete

  20. 20

    What command for showing disk usage of specific directory non recursive?

  21. 21

    What command for showing disk usage of specific directory non recursive?

  22. 22

    Allow non-root users to execute specific command

  23. 23

    How to INSERT OR UPDATE while MATCHING a non Primary Key without updating existing Primary Key?

  24. 24

    How to INSERT OR UPDATE while MATCHING a non Primary Key without updating existing Primary Key?

  25. 25

    How to compose proper insert/update/delete commands to update linked tables in source access database?

  26. 26

    How to insert, update and delete items from JTable that is loaded from (SQLite) Database

  27. 27

    Insert,update and delete data from Sql database using vb.net?

  28. 28

    Edit SQL Server Database (INSERT, UPDATE, etc) in ASP.NET (VB)

  29. 29

    How are store/website-specific (or non-global) products attributes stored/queried in the Magento mysql database?

HotTag

Archive