Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I was wondering if it was possible to update more than 1 row with a procedure, im not sure why this one isnt working. Its working only if theres only 1 row in my table. But if there's more than 1 row i get the usual error message :
ORA-01422: exact fetch returns more than requested number of rows


create or replace procedure TP3_SP_ARCHIVER_ENCAN
is

    V_CURRENT_DATE date;
    V_DATE_ENCAN date;

begin
    select sysdate, DATE_FIN_ENC into V_CURRENT_DATE, V_DATE_ENCAN from TP2_ENCAN;
    
    update TP2_ENCAN
    set EST_ARCHIVEE_ENC = 1,
    STATUT_ENC = 'Archivé'
    where V_CURRENT_DATE - V_DATE_ENCAN > 60;
  
    
end TP3_SP_ARCHIVER_ENCAN;
/


What I have tried:

I'm honestly not sure why this isnt working. Is it possible a procedure cannot update more than 1 row at once ?
Posted
Updated 15-Jul-19 17:20pm

1 solution

The error comes from the first statement where you try to fetch values multiple rows while the receiving variables (V_CURRENT_DATE, V_DATE_ENCAN) can hold only a single value.

But beyond that, as far as I can see the WHERE clause of the UPDATE statement is based purely on the received single variable values, you do not use any columns to restrict the rows. In other words, the UPDATE statement would update all rows or no rows at all, depending on the values....

So if the idea is to is to do the update based on the values of individual rows, try something like
SQL
CREATE OR REPLACE PROCEDURE TP3_SP_ARCHIVER_ENCAN 
IS
BEGIN

    UPDATE TP2_ENCAN
    SET   EST_ARCHIVEE_ENC = 1,
          STATUT_ENC = 'Archivé'
    WHERE SYSDATE - DATE_FIN_EN > 60;

END TP3_SP_ARCHIVER_ENCAN;
/
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900