用游标似乎可以。 create or replace function sp_ListEmp return types.cursortype as l_cursor types.cursorType; begin open l_cursor for select ename, empno from emp order by ename; return l_cursor; end; 但是不明白,这个东西,可以和MS SQL的select ename, empno from emp order by ename存储过程等价么??还有,效率怎么样?可以支持超大数量的的并发访问么????
up 我觉得我调有这oralce存储过程也难受。没有sqlserver的方遍
使用游标之后,客户端得到的是数据集么?(ADO.Net) 另外,这种游标,能保证效率么?
贴了好多次的代码,再帖一次,--包头 create or replace package pkg_test as type myCursor is ref cursor; function get(p_id number) return myCursor; end pkg_test; --包体 create or replace package body pkg_test as --输入ID 返回记录集的函数 function get(p_id number) return myCursor is rc myCursor; strsql varchar2(200); begin if p_id=0 then open rc for select a.user_name from fnd_user a ; else strsql:='select a.user_name from fnd_user a where a.user_id=:p_id'; open rc for strsql using p_id; end if; return rc; end get;
end pkg_test;--调用测试 set serverout on declare w_rc pkg_test.myCursor; w_name varchar2(100); begin w_rc:=pkg_test.get(0); loop fetch w_rc into w_name; exit when w_rc%notfound; dbms_output.put_line(w_name); end loop; end; /
create or replace function sp_ListEmp return types.cursortype as
l_cursor types.cursorType;
begin
open l_cursor for select ename, empno from emp order by ename;
return l_cursor;
end; 但是不明白,这个东西,可以和MS SQL的select ename, empno from emp order by ename存储过程等价么??还有,效率怎么样?可以支持超大数量的的并发访问么????
另外,这种游标,能保证效率么?
create or replace package pkg_test
as
type myCursor is ref cursor;
function get(p_id number) return myCursor;
end pkg_test;
--包体
create or replace package body pkg_test
as
--输入ID 返回记录集的函数
function get(p_id number) return myCursor is
rc myCursor;
strsql varchar2(200);
begin
if p_id=0 then
open rc for select a.user_name from fnd_user a ;
else
strsql:='select a.user_name from fnd_user a where a.user_id=:p_id';
open rc for strsql using p_id;
end if;
return rc;
end get;
end pkg_test;--调用测试
set serverout on
declare
w_rc pkg_test.myCursor;
w_name varchar2(100);
begin
w_rc:=pkg_test.get(0);
loop
fetch w_rc into w_name;
exit when w_rc%notfound;
dbms_output.put_line(w_name);
end loop;
end;
/
另外,这种游标,能保证效率么?
1.是的.
2.过程返回记录集效率还是比较高的,直接从应用程序中传递代码系统要分析,要花一定的时间,而且增加了一定的网络数据流量.
指程序中传递的SQL语句。
一来,传递SQL语句文本比较长,而存储过程只是一个很短的名字,长短比例大约是10:1。访问密集的情况下,存储过程有优势。
二来,SQL语句到数据库服务器中执行前要分析、编译;而存储过程是已经分析过、编译完成了的,可以立即执行。