Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.tools -> PL\SQL optimization for update or insert behavior
I am trying to create a PL statement that will either update an existing record or insert a new record if no existing records are found. This will eventually be used in a JDBC PreparedStatement for batch processing. Assume that there is a pretty random distribution of inserts and updates. I've come up with a few possible ways of doing this but I'm not sure which will run faster. The smallest of gains are important since it will be run possibly thousands of times (or more). The requirements for the project forbid me to use stored procedures so that is not an option.
Which of the follow statements would be the most efficient (or is there a better way)? Any help would be greatly appreciated.
Jon
DECLARE
recordFound EXCEPTION; spoo ROWID; BEGIN SELECT ROWID into spoo from JCTEST where account_number = '103'; raise recordFound; EXCEPTION when recordFound then UPDATE JCTEST SET amount = 23.23 where account_number = '103'; when no_data_found then INSERT into JCTEST VALUES ('103', 101.70);END;
![]() |
![]() |