簡體   English   中英

通過存儲過程顯示數據

[英]Displaying data through stored procedure

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;
/

您好,我正在嘗試使用存儲過程顯示來自aa表的數據。 姓氏作為參數通過存儲過程傳遞,執行時,存儲過程應顯示所有具有姓氏的行。 這是我得到的錯誤; 請幫忙! : -

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

不需要引號:

select * into row from employee where EMPLASTNAME=pEMPLASTNAME;

但是,您可能無法獲得該變量值的任何數據(即有一天,它可能會發生)這就是為什么我建議您捕獲異常並對其進行處理(參見EXCEPTION塊)

pd:不使用諸如row保留字是一種好習慣。 我建議你用另一種方式命名變量。

我建議使用光標選擇所有行,然后循環光標以打印結果:

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;
/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM