精确提取中指定的数量小于返回的行数:这是不可能的

时间:2018-04-11 13:43:44

标签: oracle plsql

我在PL / SQL中定义了以下过程:

CREATE OR REPLACE PROCEDURE deleteFromStudyCase(studycase_id IN NUMBER)
IS
   VAL_CARRIER_ID_GLOBAL  NUMBER(19,0);
   EST_OBJ_ID_GLOBAL      NUMBER(19,0);
   INVEST_TASK_ID_GLOBAL  NUMBER(19,0);
BEGIN

-- Fill the variables
SELECT IT.ID into INVEST_TASK_ID_GLOBAL
  FROM T_INVESTIGATIONTASK IT
  WHERE IT.STUDYCASE_ID = studycase_id;

SELECT EO.ID into EST_OBJ_ID_GLOBAL 
  FROM T_ESTIMATIONOBJECT EO
  WHERE EO.INVESTIGATIONTASK_ID = INVEST_TASK_ID_GLOBAL;

SELECT VC.ID into VAL_CARRIER_ID_GLOBAL
  FROM T_VALIDATIONCARRIER VC
  WHERE VC.IA_ESTIMATIONOBJECT_ID = EST_OBJ_ID_GLOBAL;

....many DELETE statements...

END deleteFromStudyCase;

当我尝试使用它时:

BEGIN
  DELETEFROMSTUDYCASE(30111);
END;

在运行时,它失败并出现此错误:

Error report -
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "DELETEFROMSTUDYCASE", line 9
ORA-06512: at line 2
01422. 00000 -  "exact fetch returns more than requested number of rows"
*Cause:    The number specified in exact fetch is less than the rows returned.
*Action:   Rewrite the query or change number of rows requested

意味着其中一个选择返回的不仅仅是预期的一个值。我试着分别运行select语句来查看哪个是问题但是:

SELECT IT.ID
  FROM T_INVESTIGATIONTASK IT
  WHERE IT.STUDYCASE_ID = 30111;

仅返回10053。

SELECT EO.ID
  FROM T_ESTIMATIONOBJECT EO
  WHERE EO.INVESTIGATIONTASK_ID = 10053;

仅返回933。

SELECT VC.ID
  FROM T_VALIDATIONCARRIER VC
  WHERE VC.IA_ESTIMATIONOBJECT_ID = 933;

仅返回12.

由于我的数据库的这一部分有树结构,我还创建了以下过程:

CREATE OR REPLACE PROCEDURE deleteFromInvestigationTask(invest_task_id IN NUMBER)
IS
  VAL_CARRIER_ID_GLOBAL NUMBER(19,0);
  EST_OBJ_ID_GLOBAL NUMBER(19,0);
BEGIN

-- Fill the variables
SELECT EO.ID into EST_OBJ_ID_GLOBAL 
  FROM T_ESTIMATIONOBJECT EO
  WHERE EO.INVESTIGATIONTASK_ID = invest_task_id;

SELECT VC.ID into VAL_CARRIER_ID_GLOBAL 
  FROM T_VALIDATIONCARRIER VC
  WHERE VC.IA_ESTIMATIONOBJECT_ID = EST_OBJ_ID_GLOBAL;

...many DELETE statements...

这个工作正常。
那么另一个应该工作,为什么我继续得到这个错误?还有什么呢?

1 个答案:

答案 0 :(得分:1)

我发现了问题。
在第一个过程中,参数名称为studycase_id,它也是表T_INVESTIGATIONTASK中列的名称,因此WHERE条件IT.STUDYCASE_ID = studycase_id是错误的:这就是为什么第一个SELECT失败了。我更改了study_case_id中的参数名称并解决了我的问题。