简体   繁体   中英

ORA-01427: single-row subquery returns more than one row with update

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 = ? 
        )

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM