Message-Id: <10617.116795@fatcity.com> From: Rajagopal Venkataramany Date: Tue, 12 Sep 2000 20:34:36 -0700 (PDT) Subject: Re: PL/SQL Question Hi, You could probably use the SELECT statement directly on the table instead of a sub-query. BEGIN SELECT 1 INTO V_VARIABLE FROM TABLE_NAME WHERE PRIMARYKEY = XXXX; V_HIT_FLAG := 1; EXCEPTION WHEN NO_DATA_FOUND THEN V_HIT_FLAG = 0; END; IF V_HIT_FLAG = 1 THEN UPDATE.... ELSE INSERT ... END IF; This should answer your question. Regards Rajagopal Venkataramany On Tue, 12 Sep 2000 19:00:34 -0800, ORACLE-L@fatcity.com wrote: > Hi, > select 1 into x from dual > where exists ( select * from table where primarykey = 1234 ); > > if x != 1 > insert > else > update > end if; > > Raman > > ---------------------------------------- Message History ---------------------------------------- > > > > Please respond to ORACLE-L@fatcity.com > > To: ORACLE-L@fatcity.com > cc: > > > > Hi! > > I do have a weird problem to solve. I wanna check if a specific record > already exists in a table (select * from table where PrimaryKey = 1234). If > it does, I wanna do an update on that record and if it doesn't, I wanna > insert a record. > > What would be the best (and least expensive) way to achieve this in a > procedure? > > Thanks, > Helmut > > -- > Author: Helmut Daiminger > INET: hdaiminger@vivonet.com > > Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051 > San Diego, California -- Public Internet access / Mailing Lists > -------------------------------------------------------------------- > To REMOVE yourself from this mailing list, send an E-Mail message > to: ListGuru@fatcity.com (note EXACT spelling of 'ListGuru') and in > the message BODY, include a line containing: UNSUB ORACLE-L > (or the name of mailing list you want to be removed from). You may > also send the HELP command for other information (like subscribing). > > > > > -- > Author: > INET: raman.yagna@db.com > > Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051 > San Diego, California -- Public Internet access / Mailing Lists > -------------------------------------------------------------------- > To REMOVE yourself from this mailing list, send an E-Mail message > to: ListGuru@fatcity.com (note EXACT spelling of 'ListGuru') and in > the message BODY, include a line containing: UNSUB ORACLE-L > (or the name of mailing list you want to be removed from). You may > also send the HELP command for other information (like subscribing). Regards Rajagopal Venkataramany _______________________________________________________