“ ORA-01422:精确获取返回的行数超过了请求的行数”我在执行块时遇到此错误

时间:2019-10-24 09:55:35

标签: plsql

我希望使用plsql块显示4列,但是我无法运行编写的代码。有什么建议吗?

   DECLARE
    rsid    objectbase.asset_id%TYPE;
    obid    i18n_objectbase.object_id%TYPE;
    nme     i18n_objectbase.name%TYPE;
    descp   i18n_objectbase.short_description%TYPE;
BEGIN
    SELECT
        ob.asset_id,
        o.object_id,
        o.name,
        o.short_description
    INTO
        rsid,
        obid,
        nme,
        descp
    FROM
        objectbase        ob
        JOIN i18n_objectbase   o ON ( ob.object_id = o.object_id );

    dbms_output.put_line(rsid
                         || obid
                         || nme
                         || descp);
END;
/

1 个答案:

答案 0 :(得分:0)

类似这样的方法可以解决问题,但是我不确定为什么您需要这种PL SQL代码(请注意,我已经简化了where部分)...在这里:

DECLARE
   rsid    varchar2(100);
   obid    varchar2(100);
   nme     varchar2(100);
   descp   varchar2(100);

   cursor c_test
   is
   SELECT ob.asset_id
          , ob.object_id
          , ob.name
          , ob.short_description
   FROM objectbase ob;
BEGIN

   FOR i in c_test loop

      rsid := i.asset_id;
      obid := i.object_id;
      nme := i.name;
      descp := i.short_description;

      dbms_output.put_line(rsid
                        || obid
                        || nme
                        || descp);

   END LOOP;
END;

这里是DEMO

然后使用此:

DECLARE
    rsid    varchar2(100);
    obid    varchar2(100);
    nme     varchar2(100);
    descp   varchar2(100);

BEGIN
    FOR i IN (SELECT  ob.asset_id
                      , ob.object_id 
                      , ob.name
                      , ob.short_description
              FROM objectbase ob) LOOP

       rsid := i.asset_id;
       obid := i.object_id;
       nme := i.name;
       descp := i.short_description;

       dbms_output.put_line(rsid
                         || obid
                         || nme
                         || descp);

    END LOOP;
END;
/

这里是DEMO

这是表和列的代码:

DECLARE
    rsid    objectbase.asset_id%TYPE;
    obid    i18n_objectbase.object_id%TYPE;
    nme     i18n_objectbase.name%TYPE;
    descp   i18n_objectbase.short_description%TYPE;
BEGIN

    FOR i IN (SELECT
        ob.asset_id,
        o.object_id,
        o.name,
        o.short_description
    FROM
        objectbase ob
        JOIN i18n_objectbase o ON ( ob.object_id = o.object_id )) loop

        rsid := i.asset_id;
        obid := i.object_id;
        nme := i.name;
        descp := i.short_description;

        dbms_output.put_line(rsid
                         || obid
                         || nme
                         || descp);
    END LOOP;
END;