PLSQL 未找到数据

Posted

技术标签:

【中文标题】PLSQL 未找到数据【英文标题】:PLSQL no data found 【发布时间】:2021-12-13 12:33:31 【问题描述】:

我有一个新问题和新问题 :) 我想将数据保存在表中,但 Oracle 不能这样做。他给出错误 ora-01403 no data found。在下面的代码中我找不到然后是这个错误。感谢您的帮助。

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);

在下一节中我想在表格中插入数据

        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;

在下一节中我发现了一些价值

        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;

在下一节中我想在表格中插入数据

        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;

【问题讨论】:

SYSDATE 返回一个DATE 值,从不在已经是DATE 的值上使用TO_DATE()。也许您正在寻找TRUNC(SYSDATE) 【参考方案1】:

您发布的代码中有 3 个 SELECT ... INTO 语句:

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;

其中至少有一个没有找到任何结果并返回了NO_DATA_FOUND 错误。哪一个?不知道,你必须自己调试它,看看你会怎么做:

处理异常,或 修复您编写的代码

【讨论】:

以上是关于PLSQL 未找到数据的主要内容,如果未能解决你的问题,请参考以下文章

PLSQL 触发器 ORA 01403 未找到数据

在循环游标中未找到数据

plsql表更新后视图未更新

plsql 不能初始化

plsql developer 编辑存储过程 未响应

如何解决没有找到数据的plsql中的错误