网站页面设计公司电话,为什么推荐企业做网站,惠州免费建站模板,wordpress 数据图片存在哪如何从存储过程返回多行#xff1f; (Oracle PL / SQL)我想用一个参数创建一个存储过程#xff0c;该存储过程将根据参数返回不同的记录集。 这是怎么做的#xff1f; 我可以从普通SQL中调用它吗#xff1f;5个解决方案65 votes这是如何构建一个函数#xff0c;该函数返回…如何从存储过程返回多行 (Oracle PL / SQL)我想用一个参数创建一个存储过程该存储过程将根据参数返回不同的记录集。 这是怎么做的 我可以从普通SQL中调用它吗5个解决方案65 votes这是如何构建一个函数该函数返回可以像表一样查询的结果集SQL create type emp_obj is object (empno number, ename varchar2(10));2 /Type created.SQL create type emp_tab is table of emp_obj;2 /Type created.SQL create or replace function all_emps return emp_tab2 is3 l_emp_tab emp_tab : emp_tab();4 n integer : 0;5 begin6 for r in (select empno, ename from emp)7 loop8 l_emp_tab.extend;9 n : n 1;10 l_emp_tab(n) : emp_obj(r.empno, r.ename);11 end loop;12 return l_emp_tab;13 end;14 /Function created.SQL select * from table (all_emps);EMPNO ENAME---------- ----------7369 SMITH7499 ALLEN7521 WARD7566 JONES7654 MARTIN7698 BLAKE7782 CLARK7788 SCOTT7839 KING7844 TURNER7902 FORD7934 MILLERTony Andrews answered 2020-06-30T04:27:23Z22 votes我认为您想返回一个REFCURSORcreate function test_cursorreturn sys_refcursorisc_result sys_refcursor;beginopen c_result forselect * from dual;return c_result;end;更新如果需要从SQL调用此函数请使用建议使用的表函数例如Tony Andrews。Thilo answered 2020-06-30T04:27:48Z8 votes您可以使用Oracle流水线函数基本上当您希望将PLSQL(或Java或C)例程作为“源”时 数据-而不是表-您将使用流水线函数。简单示例-生成一些随机数据如何根据输入参数创建N个唯一的随机数create type arrayas table of number;create function gen_numbers(n in number default null)return arrayPIPELINEDasbeginfor i in 1 .. nvl(n,999999999)looppipe row(i);end loop;return;end;假设我们需要三行内容。 现在我们可以通过以下两种方式之一进行操作select * from TABLE(gen_numbers(3));COLUMN_VALUE123要么select * from TABLE(gen_numbers)where rownum 3;COLUMN_VALUE123管道功能1管道功能2Mohsen Heydari answered 2020-06-30T04:28:45Z3 votes如果要在普通SQL中使用它我将让存储过程使用结果行填充表或临时表(或使用Tony Andrews方法)。如果要使用Thilo的解决方案则必须使用PL / SQL循环游标。这是一个示例(我使用了过程而不是函数就像Thilo一样)create or replace procedure myprocedure(retval in out sys_refcursor) isbeginopen retval forselect TABLE_NAME from user_tables;end myprocedure;declaremyrefcur sys_refcursor;tablename user_tables.TABLE_NAME%type;beginmyprocedure(myrefcur);loopfetch myrefcur into tablename;exit when myrefcur%notfound;dbms_output.put_line(tablename);end loop;close myrefcur;end;John Smithers answered 2020-06-30T04:29:10Z1 votescreate procedure (p_cur out sys_refcursor) as begin open p_cur for select * from end;S. Mayol answered 2020-06-30T04:29:26Z