oracle ora-01422,Oracle/PLSQL: ORA-01422

I create a test procedure:

CREATE OR REPLACE PROCEDURE PROCE_0(

ival IN OSM_TAB_PROCE.COL_0%TYPE:=10,

ocnt IN OUT NUMBER)

AS

a OSM_TAB_PROCE.COL_0%TYPE;

r OSM_TAB_PROCE%ROWTYPE;

i NUMBER := 0;

CURSOR c1(ct0 NUMBER) IS SELECT COL_0 FROM OSM_DML_2SP.OSM_TAB_PROCE WHERE COL_0>ct0;BEGIN

IF c1%ISOPEN=FALSE THEN

OPEN c1(196);

END IF;

LOOP

FETCH c1 INTO a;

EXIT WHEN c1%NOTFOUND;

SELECT COL_0,COL_1,COL_2 INTO r FROM OSM_DML_2SP.OSM_TAB_PROCE

WHERE COL_0=a AND ROWNUM<2; -- if ROWNUM < 2 delete then ORA-01422

r.COL_0 := a + ival;

r.COL_2 := TO_CHAR(a) || TO_CHAR(SYSDATE);

INSERT INTO OSM_DML_2SP.OSM_TAB_PROCE VALUES r;

i := i + 1;

END LOOP;

CLOSE c1;

ocnt := i;

END;

Error Message:

Error:     ORA-01422: exact fetch returns more than requested number of rows

Cause:     You tried to execute a SELECT INTO statement and more than one row was returned.

Action: The options to resolve this Oracle error are:

1. Rewrite your SELECT INTO statement so that only one row is returned.

2. Replace your SELECT INTO statement with a cursor.

For example, if you tried to execute the following SQL statement:

SELECT supplier_id

INTO cnumber

from suppliers

where supplier_name = 'IBM';

And there was more than one record in the suppliers table with the supplier_name of IBM, you would receive the ORA-01422 error message.

In this case, it might be more prudent to create a cursor and retrieve each row if you are unsure of how many records you might retrieve.

Error Message Ref:

阅读(2472) | 评论(0) | 转发(0) |

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值