I'm trying to INSERT a single record into a table and return the sequence number that was added to the record via ASP.net/Visual Studio. However, I'm receiving the above referenced error. Initially I thought my error was because it thought I might return more than one record, but even after rewriting several ways, the error continues. Multiple posts exist on this topic, but they all seem to revolve around the possibility of multiple records being inserted.
I suspect because I'm using a "select... from dual" that it still thinks I could insert more than one record. I obviously don't need the "select...from dual" except that I'd like to use a WHERE clause to guarantee that the record doesn't already exist in the destination table.
Any help or suggestions would be greatly appreciated. Thank you.
INSERT INTO blatchildren
(blatranscriptid, childactivityid, enrollmentDate, enrollmentStatus)
SELECT 2,
'cours000000000004981',
to_date('1/1/2015 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'),
'E'
from dual
where 'cours000000000004981' not in (select childactivityid from blatchildren)
returning id
into :identity
To test the code, I've been running the following in PL/SQL Developer:
declare identity number(2);
begin
INSERT INTO blatchildren
(blatranscriptid, childactivityid, enrollmentDate, enrollmentStatus)
VALUES( 2,
'cours000000000004981',
to_date('1/1/2015 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'),
'E')
returning id
into identity;
end;