Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: INSERT INTO if UPDATE SET fails (MySQL)
SQL has two separate commands:
update and insert.
You need to have a function that tries to update, or upon failure does the insert. This can be done in SQL if your database lets you write your own database functions (oracle does).
funcion my_update(parameters) return VARCHAR2 is
BEGIN
update the_table
set something = aparameter
where somethingelse = another_parameter
IF sql%rowcount = 0 then
insert into the_table (columns)
values (parameters)
END IF;
RETURN ('SUCCESS');
EXCEPTION
WHEN OTHERS THEN
RETURN (sqlerrm) ;
END;
then you can use any sql such as:
select my_update(parameters)
from dual;
and if this returns 'SUCCESS' then all is good.
Basically you need middleware (either in your application, on the database, or wherever it lives) SQL itself, does not support it. Received on Fri Oct 16 1998 - 00:00:00 CDT