[英]What is the best way to retrieve data from an oracle table using odp.net and pl/sql stored procedures?
I need to retrieve data from an oracle table using a pl/sql stored procedure and odp.net. 我需要使用pl / sql存储过程和odp.net从oracle表中检索数据。 What is the standard way of doing this? 这样做的标准方法是什么?
PL/SQL has the ability to return sets of data using Ref Cursors, which are basically pointers. PL / SQL能够使用基本为指针的Ref Cursors返回数据集。 Here is a simple function which returns a sub-set of employees based on department: 这是一个简单的函数,可根据部门返回员工子集:
SQL> create or replace function get_emps_by_dept (dno number)
2 return sys_refcursor
3 is
4 rc sys_refcursor;
5 begin
6 open rc for select * from emp where deptno = dno;
7 return rc;
8 end;
9 /
Function created.
SQL>
Here's how in works in SQL*Plus: 这是SQL * Plus中in的工作方式:
SQL> var rc refcursor
SQL> exec :rc := get_emps_by_dept(50)
PL/SQL procedure successfully completed.
SQL> print rc
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
8085 TRICHLER PLUMBER 8061 08-APR-10 3500 50
8060 VERREYNNE PLUMBER 8061 08-APR-08 4000 50
8061 FEUERSTEIN PLUMBER 7839 27-FEB-10 4500 50
8100 PODER PLUMBER 8061 3750 50
SQL>
With regards to .Net, there is a OracleRefCursor
class amongst the Oracle.DataAccess.Types . 关于.Net,在Oracle.DataAccess.Types中有一个OracleRefCursor
类。 A certain amount of plumbing is required, but the excellent Mark A Williams has written a good article on this topic, which you can find on the OTN site . 需要一定数量的管道,但是出色的Mark A Williams在该主题上写了一篇不错的文章,您可以在OTN网站上找到该文章 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.