Home » SQL & PL/SQL » SQL & PL/SQL » insert data unless its already inserted
insert data unless its already inserted [message #243136] Wed, 06 June 2007 04:00 Go to next message
gtriant
Messages: 42
Registered: September 2006
Member
Hi!
What i need to do is insert a new row in a table, unless this row already exists.
Can this be done with one query???
The table of course has primary keys.
Any ideas???
Re: insert data unless its already inserted [message #243139 is a reply to message #243136] Wed, 06 June 2007 04:02 Go to previous messageGo to next message
Michel Cadot
Messages: 68718
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Have a look at MERGE statement.

Regards
Michel
Re: insert data unless its already inserted [message #243215 is a reply to message #243139] Wed, 06 June 2007 08:38 Go to previous messageGo to next message
gtriant
Messages: 42
Registered: September 2006
Member
merge is not supported in my oracle edition (8).
any other suggestions???

[Updated on: Wed, 06 June 2007 08:45] by Moderator

Report message to a moderator

Re: insert data unless its already inserted [message #243216 is a reply to message #243136] Wed, 06 June 2007 08:39 Go to previous messageGo to next message
gtriant
Messages: 42
Registered: September 2006
Member
(the smily above was accidental!)

merge is not supported in my oracle edition (edition 8)
any other suggestions???

[Updated on: Wed, 06 June 2007 08:45] by Moderator

Report message to a moderator

Re: insert data unless its already inserted [message #243219 is a reply to message #243136] Wed, 06 June 2007 08:41 Go to previous messageGo to next message
gtriant
Messages: 42
Registered: September 2006
Member
that's why the preview is for.....

anyway my oracle edition is 8.
merge is not supported...

Re: insert data unless its already inserted [message #243220 is a reply to message #243216] Wed, 06 June 2007 08:42 Go to previous messageGo to next message
Michel Cadot
Messages: 68718
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Yes, post your oracle version (4 decimals).

OK, you wrote at the same time.

Regards
Michel

[Updated on: Wed, 06 June 2007 08:42]

Report message to a moderator

Re: insert data unless its already inserted [message #243221 is a reply to message #243219] Wed, 06 June 2007 08:46 Go to previous messageGo to next message
Michel Cadot
Messages: 68718
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
begin
  insert ...
exception
  when when DUP_VAL_ON_INDEX then null;
end;
/

Regards
Michel
Re: insert data unless its already inserted [message #243224 is a reply to message #243221] Wed, 06 June 2007 09:06 Go to previous messageGo to next message
gtriant
Messages: 42
Registered: September 2006
Member
i need it to be a plain query, because it will have to be executed within java code.
thanks anyway. i'll go an oldfashioned way.
Re: insert data unless its already inserted [message #243227 is a reply to message #243224] Wed, 06 June 2007 09:14 Go to previous message
Michel Cadot
Messages: 68718
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Java can execute PL/SQL code.

Regards
Michel
Previous Topic: Spooling of Records
Next Topic: How to generate SQL query
Goto Forum:
  


Current Time: Thu Dec 05 06:18:24 CST 2024