2013-11-22 153 views
0
Create or replace procedure disp(pEMPLASTNAME varchar2) 
IS 
Row employee%rowtype; 
begin 
select * into row from employee where EMPLASTNAME=’pEMPLASTNAME’ ; 
dbms_output.put_line('Name: '||Row.EMPID||' '|| Row.EMPNAME); 
End; 
/

BEGIN 
disp(‘Mark’); 
END; 
/

您好,我试图使用存储过程显示表中的数据。姓氏通过存储过程作为参数传递,并且在执行时,存储过程应显示具有姓氏的所有行。这是我得到的错误;请帮忙! : -通过存储过程显示数据

SQL> BEGIN 
disp('Mark'); 
END; 
/
BEGIN 
* 
ERROR at line 1: 
ORA-01403: no data found 
ORA-06512: at "TEST.DISP", line 5 
ORA-06512: at line 2 

回答

1

无需引号的:

select * into row from employee where EMPLASTNAME=pEMPLASTNAME; 

但是,您可能没有该变量值的任何数据呢(即有一天,它可能发生) 这就是为什么我建议你发现异常并予以处理(见EXCEPTION区块)

pd:不使用保留字如row是一种好习惯。我建议你以另一种方式命名变量。

+0

谢谢,但现在我得到这个错误: - –

+0

ORA-01422:精确获取回报更多比要求的行数 –

+0

@Nidhin_toms,这意味着不止一名员工的姓氏像'Mark'。这个pl/sql块只允许返回一行。 – Sebas

1

我会建议使用光标选择所有行,然后通过游标循环打印结果:

Create or replace procedure disp(pEMPLASTNAME varchar2) 
IS 
Cursor row_select is 
    select EMPID, EMPNAME from employee where emplastname = pEMPLASTNAME; 
-- and whatever columns you need to print, using * isn't good practice 

begin 
for item in row_select loop 
    dbms_output.put_line('Name: '||item.EMPID||' '|| item.EMPNAME); 
end loop; 
End; 
/

BEGIN 
disp(‘Mark’); 
END; 
/
+0

非常感谢您的输入Armunin! –