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 -> Newbie want to insert a row ...

Newbie want to insert a row ...

From: Newbie <midifree_at_free.fr>
Date: 2000/09/21
Message-ID: <J1jy5.1469$kR.4895881@nnrp2.proxad.net>#1/1

Hi,
I work on PL/SQL and i want to insert a row if it's not yet inserted :

MyTable(PrimaryKey, Field)

What's the best solution to insert a row if it's not yet inserted in this table and is there better solution ?
1:
BEGIN
    INSERT INTO MyTable(PrimaryKey, Field) Values ('KeyValue',
'FieldValue');

EXCEPTION
WHEN DUP_VAL_ON_INDEX THEN
               NULL;
END; 2 : -- I think that this solution can don't work properly sometime : DECLARE
Cpt NUMBER;
BEGIN
    SELECT COUNT(0) INTO Cpt FROM MyTable WHERE PrimaryKey = 'KeyValue';     IF Cpt = 0 THEN

        INSERT INTO MyTable(PrimaryKey, Field) Values ('KeyValue',
'FieldValue');

    END IF;
END; 3 : ????

Thanks a lot Received on Thu Sep 21 2000 - 00:00:00 CDT

Original text of this message

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