Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.tools -> Newbie want to insert a row ...
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