Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.tools -> PL\SQL optimization for update or insert behavior

PL\SQL optimization for update or insert behavior

From: Jon <jumper_at_engineer.com>
Date: 25 Jul 2001 06:40:28 -0700
Message-ID: <1b9d847.0107250540.789992d1@posting.google.com>

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; Received on Wed Jul 25 2001 - 08:40:28 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US