PLSQL no data found

Viewed 36

I have a new problem and new question :) I want to save data in table but Oracle can't do this. He give error ora-01403 no data found. In code below I can't find then is this error. Thanks for helping.

DECLARE
    CURSOR c_data IS
    SELECT
        ROWID, td.*
    FROM cols td
    WHERE td.col1 IS NOT NULL AND td.col2 IS NOT NULL AND td.col3 IS NOT NULL AND td.col4 IS NOT NULL AND td.col5 IS NOT NULL AND td.col6 IS NOT NULL
        AND td.col7 IS NOT NULL OR td.col8 IS NOT NULL OR td.col9 IS NOT NULL OR td.col10 IS NOT NULL;

    c_id            NUMBER;
    r_number        NUMBER;
    editor     NUMBER;
    intendant  NUMBER;
    supersu       NUMBER;
BEGIN

    FOR i IN c_data LOOP
        c_id := 0;
        r_number := 0;
        r_number := random_number();
        c_id := fn_name(i.col5);

in next section I want to insert data in table

        INSERT INTO obj.tb@link_name (
            first,
            ip,
            cuname,
            data1,
            tp,
            lastest,
            middle,
            date3,
            date2,
            date
        ) VALUES (
            i.col1,
            i.col8 || i.col9,
            c_id,
            to_date(sysdate, 'MM/DD/YYYY'),
                CASE
                    WHEN i.col8 IS NOT NULL THEN
                        (
                            SELECT tp
                            FROM vtp
                            WHERE tp = 10
                        )
                    ELSE
                        (
                            SELECT tp
                            FROM vtp
                            WHERE tp = 20
                        )
                END,
            i.col3,
            i.col2,
            to_date(i.col4, 'MM/DD/YYYY'),
            to_date(i.col6, 'MM/DD/YYYY'),
            to_date(i.col7, 'MM/DD/YYYY')
        );
        COMMIT;

in next section I find some value

        SELECT DISTINCT ( ed ) NTO editor
        FROM dt_table_2
        WHERE upper(first) LIKE upper(i.col1) AND upper(last) LIKE upper(i.col3) AND upper(middle) LIKE upper(i.col2) AND ROWNUM = 1;
        SELECT DISTINCT ( numberVar ) INTO intendant
        FROM dt_table_1
        WHERE numberVar = :p13_apex_item AND ROWNUM = 1;

in next section I want to insert data in table

        INSERT INTO obj.tb2@link_name (
            nb_val,
            nb_val2
        ) VALUES (
            1,
            editor
        );
        COMMIT;
        SELECT DISTINCT ( st ) INTO supersu
        FROM obj.tbd12@link_name
        WHERE ed = editor AND ROWNUM = 1;
        INSERT INTO obj.tdb3@link_name (
            data1,
            solus,
            snumber,
            ter,
            sd,
            ad,
            dd,
            ed,
            ssd,
            data2,
            id
        ) VALUES (
            to_date(sysdate, 'MM/DD/YYYY'),
            intendant,
            r_number,
            to_date(sysdate + 5, 'MM/DD/YYYY'),
            1,
            1,
            1,
            editor,
            supersu,
            to_date(sysdate, 'MM/DD/YYYY'),
            intendant
        );
        COMMIT;
    END LOOP;
END;

1 Answers

There are 3 SELECT ... INTO statements in code you posted:

SELECT DISTINCT (ed)
  INTO editor
  FROM dt_table_2
 WHERE     UPPER (FIRST) LIKE UPPER (i.col1)
       AND UPPER (LAST) LIKE UPPER (i.col3)
       AND UPPER (middle) LIKE UPPER (i.col2)
       AND ROWNUM = 1;

SELECT DISTINCT (numbervar)
  INTO intendant
  FROM dt_table_1
 WHERE     numbervar = :p13_apex_item
       AND ROWNUM = 1;

SELECT DISTINCT (st)
  INTO supersu
  FROM obj.tbd12@link_name
 WHERE     ed = editor
       AND ROWNUM = 1;

At least one of them didn't find any results and has returned the NO_DATA_FOUND error. Which one? No idea, you'll have to debug it yourself and see what you'll going to do about it:

  • handle the exception, or
  • fix code you wrote
Related