错误消息:ORA-01403:未找到任何数据

时间:2016-04-03 19:21:04

标签: oracle-sqldeveloper

我是Oracle SQL Developer中的新编码,现在我已经完成了列出我插入类别中所有项目的任务。我一直得到“错误消息:ORA-01403:没有找到数据”或错误消息,他们说我有太多行。有人可以看看我的代码吗?

procedure LIST_PROJECTS_PP ( --Elaine
p_catName           IN VARCHAR2      -- required
)

IS 
  ex_ERROR             EXCEPTION;
  ex_errorMsg_txt      VARCHAR(100);
  v_catName_txt        GG_Projcat.Category_Name%type;
  v_projstatus_txt     GG_Project.Project_Status%type;
  v_projtitle_txt      GG_Project.Project_Title%type;
  v_projorg_txt        GG_Project.Org_ID%type;
  v_projcount_txt      GG_Project.Country_ISO3166%type;
  v_projgoal_txt       GG_Project.Project_Goal%type;
  v_projID_txt         GG_Project.Project_ID%type;

BEGIN
  SELECT GG_PROJECT.Project_Title, GG_PROJECT.Project_ID, GG_PROJCAT.Category_Name, GG_PROJECT.Project_Status INTO v_projtitle_txt, v_projID_txt, v_catname_txt, v_projstatus_txt
  FROM GG_PROJECT, GG_PROJCAT
  WHERE GG_PROJECT.PROJECT_ID = GG_PROJCAT.PROJECT_ID
  AND p_catname = category_name
  AND GG_PROJECT.PROJECT_STATUS = 'active';
  COMMIT;
  DBMS_output.put_line('Project Title: '|| v_projtitle_txt);

  IF v_catname_txt IS NULL THEN
    ex_errorMsg_txt := 'Category does not exist';
    RAISE ex_ERROR;
  END IF;

EXCEPTION
  WHEN ex_ERROR THEN
  DBMS_OUTPUT.PUT_LINE (ex_errorMsg_txt);
  WHEN OTHERS THEN
  DBMS_OUTPUT.PUT_LINE ('An error occured.') ;
  DBMS_OUTPUT.PUT_LINE ('Error code:  ' || SQLCODE) ;
  DBMS_OUTPUT.PUT_LINE ('Error message:' || SQLERRM) ;
END LIST_PROJECTS_PP;

1 个答案:

答案 0 :(得分:1)

要在过程中接收多行,必须使用游标:

FOR rec in (SELECT GG_PROJECT.Project_Title, GG_PROJECT.Project_ID, GG_PROJCAT.Category_Name, GG_PROJECT.Project_Status INTO v_projtitle_txt, v_projID_txt, v_catname_txt, v_projstatus_txt
  FROM GG_PROJECT, GG_PROJCAT
  WHERE GG_PROJECT.PROJECT_ID = GG_PROJCAT.PROJECT_ID
 AND p_catname = category_name
 AND GG_PROJECT.PROJECT_STATUS = 'active') LOOP
   DBMS_output.put_line('Project Title: '|| rec.Project_Title);
end loop;