PL/SQL Procedure: How return a select statement?

落花浮王杯 提交于 2020-01-04 08:18:01

问题


I want to create a stored procedure on ORACLE database server and my problem is that, I don't know how can I return a select statement .

Here is the logic, which should within the procedure:

Input paramters: filter1 (int), filter2 (string)

with cte as
(
    select  val1, val2, stddev(val3) from tab1 where parameter1 = filter1 and paramter = filter1 group by val 1, val2
)
 SELECT cte.*,
    round(some calculation) as final_results FROM cte

Afterwards I want to use this procedure in a MS asp.net application, with help of the MS ADO.net and MS Entity Framework 4.2.

Lot of thanks, for your response!


回答1:


In Oracle we have to use Ref Cursors to acheive this. The very latest version of ODP .Net supports Ref Cursor binding for Entity Framework 4.x. Find out more.

Of course if you're not using Oracle 11gR2 you're probably out of luck, and you'll need to use one of the other suggestions (such as Pipelined functions).




回答2:


To return the result of a SELECT in Oracle you would use a "pipelined table function".

Please refer to the manual for a description and an example:

http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/tuning.htm#i53109

Here are some more examples from other sites:

http://www.oracle-developer.net/display.php?id=207
http://www.oracle-base.com/articles/misc/PipelinedTableFunctions.php
http://psoug.org/reference/pipelined.html




回答3:


Either create a VIEW or a FUNCTION. Stored procedures in Oracle do not return table results like in TSQL.



来源:https://stackoverflow.com/questions/8987886/pl-sql-procedure-how-return-a-select-statement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!