sql—如何在oracle中执行存储过程

i34xakig  于 2021-08-13  发布在  Java
关注(0)|答案(1)|浏览(330)

**结束。**此问题需要详细的调试信息。它目前不接受答案。
**想改进这个问题吗?**更新问题,使其成为堆栈溢出的主题。

11个月前关门了。
改进这个问题
我已经写了一个存储过程,我想执行它。
程序如下:

create or replace procedure details( p_cursor OUT SYS_REFCURSOR)
is
begin
    OPEN p_cursor FOR
       select name,address,phone,email
       from client
       join ccondition on ccondition.clientno=client.clientno
       where condition!='Acrophobia' and condition!='Heart Condition';

END details;

我尝试了不同的方法来执行,但是当我尝试每一种方法时,我得到了不同类型的错误。

dced5bon

dced5bon1#

因为过程通过 OUT 参数,则必须声明将接受它的内容。因为我没有你的table,我就用斯科特的 EMP ,只是为了展示它在sql*plus中的工作方式。

SQL> create or replace procedure details (p_cursor out sys_refcursor)
  2  is
  3  begin
  4    open p_cursor for
  5      select empno, ename, job, sal
  6      from emp
  7      where deptno = 10;
  8  end;
  9  /

Procedure created.

SQL> var rc refcursor;
SQL>
SQL> begin
  2    details (:rc);
  3  end;
  4  /

PL/SQL procedure successfully completed.

SQL> print rc

     EMPNO ENAME      JOB              SAL
---------- ---------- --------- ----------
      7782 CLARK      MANAGER         2450
      7839 KING       PRESIDENT       5000
      7934 MILLER     CLERK           1300

SQL>

如果你发布了你尝试过的东西,这样我们就可以帮助你修复这些错误(如果可能的话),因为-也许你想要其他的选择。
如果您使用oracle live sql,类似这样的操作可以完成这项工作:

create table emp as
  select 7782 empno, 'CLARK' ename from dual union all
  select 7839      , 'KING'        from dual union all
  select 7934      , 'MILLER'      from dual;

create or replace procedure details (p_cursor out sys_refcursor)
is
begin
  open p_cursor for
    select empno, ename
    from emp;
end;
/

declare
  rc sys_refcursor;
  l_empno emp.empno%type;
  l_ename emp.ename%type;
begin
  details (rc);
  loop
    fetch rc into l_empno, l_ename;
    exit when rc%notfound;
    dbms_output.put_line(l_empno||' - '|| l_ename);
  end loop;
end;
/

相关问题