0
votes

I have an update statement, at first it worked with some data, but after a while I've been having issues with some regiters , I got the following error: ORA-01427: single-row subquery returns more than one row . I thought it was the IN because the query might return repeated IDs, so I put a DISTINCT but I kept getting the same error, does anyone have any idea what could it be?

The query below:

 UPDATE 
        TABLE_DETAIL DET 
    SET 
        DET.ACCEPTED=?,
        DET.VALUE_ACCEPTED=(SELECT RES.VALUE FROM TABLE_RES RES WHERE RES.MYT=DET.MYT AND RES.RAD=DET.RAD AND RES.ITEM=DET.ITEM), 
    WHERE 
        DET.ID 
    IN (
        SELECT 
            DISTINCT DET_I.ID
            FROM TABLE_DETAIL DET_I, TABLE_RES RES_I, TABLE_REC REC 
            WHERE 
                DET_I.MYT = ? 
            AND 
                REC.TEMP 
                NOT IN (
                    SELECT DISTINCT TEMP 
                    FROM 
                    TABLE_IMAGES WHERE CODE=?) 
            AND RES_I.USER = ? 
        )
1
It's the DET.VALUE_ACCEPTED=(SELECT RES.VALUE FROM... sub-query that causes trouble.jarlh

1 Answers

0
votes

You don't need SELECT DISTINCT with IN.

The proximal cause of your problem is this code:

    DET.VALUE_ACCEPTED = (SELECT RES.VALUE FROM TABLE_RES RES WHERE RES.MYT=DET.MYT AND RES.RAD=DET.RAD AND RES.ITEM=DET.ITEM), 

It isn't really possible to say how to fix it. The error code seems pretty clear: More than one row is returned by this query.

You can add WHERE rownum = 1 if you want an arbitrary value. Or an aggregation function in the SELECT.