I have the following procedure:
CREATE OR REPLACE PROCEDURE My_Procedure
AS
CURSOR proced IS
SELECT aID FROM A;
BEGIN
FOR row IN proced LOOP
INSERT INTO AQ VALUES (row.aID, AQ_NT(AQT('',NULL, '', '')));
DELETE TABLE (SELECT Q FROM AQ) AQT WHERE AQT.Year=NULL;
END LOOP;
END My_Procedure;
/
And the procedure creates fine, but I have a problem in executing it, I am using the following command:
EXECUTE My_Procedure;
But i get the following error:
ERROR at line 1:
ORA-01427: single-row subquery returns more than one row
ORA-06512: at “SMITH. My_Procedure”, LINE 8
Ora-06512: at line 1
I have been at this for weeks, I am 100% sure the command for the execute is correct. And ORACLE 10G creates the procedure fine so please can you provide help which I can solve this problem.
Thank You so much
Your procedure only works if input table A contains one row.
With DELETE TABLE() you are trying to delete some rows from the nested table (AQ.Q), but the DELETE TABLE() works only if you provide one, and only one, nested table (that is, one row of AQ that contains one nested table AQ.Q, that possibly contains many nested rows or zero nested rows). In other words, DELETE TABLE(blabla) only works if blabla returns a single-row, single-column result.
Once you have two rows inserted into AQ, your sub-query
(SELECT Q FROM AQ)returns two rows and you have an ORA-01427 error.Side note: Repeating after A.B.Cade’s comment,
AQT.Year=NULLwill give misleading results in SQL, because NULL=NULL does not hold true. Better useAQT.Year IS NULL.