Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: SQL update/insert statement.
In article <8bo31k$aae$1_at_nnrp1.deja.com>,
Sean <dolans_at_my-deja.com> wrote:
> I have a table that I want to either update the counter on or else
> insert a new record if it doesn't exist.
>
> In PL/SQL I can do a count(id) on the table and update it if > 0 or
> insert if not there ( equals 0 )
>
> Is there a more efficient way of doing this in an SQL Statement?
Yes, define a cursor and use FOUND, ex:
declare
cursor my_cur is
select some_columns
from my_table
where some_clause
for update;
my_rec my_cur%rowtype;
begin
open my_cur;
fetch my_cur into my_rec;
if (my_cur%found) then
update my_table
set your_columns=your_values where current of my_cur;
hih
--
If the human brain were so simple
that we could understand it,
we would be so simple we couldn't.
-Makes Sense... don't it?
Sent via Deja.com http://www.deja.com/
Before you buy.
Received on Mon Mar 27 2000 - 12:54:55 CST
![]() |
![]() |