|
|
下面的例子用打印输出进行演示:
[php]
Create Or Replace Procedure Sp_Test(p_Num In Number) Is
Type Ref_Cur Is Ref Cursor;
l_Cur Ref_Cur;
l_Sql Varchar2(300);
l_Num Number;
l_Empno Emp.Empno%Type;
l_Ename Emp.Ename%Type;
Begin
l_Sql := 'select ' || p_Num || ',empno,ename from emp where empno > ' ||
p_Num;
Open l_Cur For l_Sql;
Loop
Fetch l_Cur
Into l_Num, l_Empno, l_Ename;
Exit When l_Cur%Notfound;
Dbms_Output.Put_Line(l_Num || ' ' || l_Empno || ' ' || l_Ename);
End Loop;
Close l_Cur;
Exception
When Others Then
If l_Cur%Isopen Then
Close l_Cur;
End If;
End Sp_Test;
wyq@ORCL>exec sp_test(7900);
7900 7902 Ford
7900 7934 Miller
PL/SQL procedure successfully completed.
wyq@ORCL>exec sp_test(7698);
7698 7782 Clark
7698 7788 Scott
7698 7839 King
7698 7844 TURNER
7698 7876 Adams
7698 7900 JAMES
7698 7902 Ford
7698 7934 Miller
PL/SQL procedure successfully completed.
wyq@ORCL>exec sp_test(8000);
PL/SQL procedure successfully completed.
wyq@ORCL>
[/php] |
|