SQL Developer Oracle,如何调用程序?

时间:2015-11-25 10:53:40

标签: oracle plsql oracle-sqldeveloper execute

我有这样的功能:

CREATE or replace PROCEDURE proc
(
  P_ID IN INTEGER,
  NAME OUT CHAR,
  SURNAME OUT CHAR,
  TOTAL OUT CHAR
)
 AS
    BEGIN
        SELECT NAME, SURNAME, sum(TOTAL) AS TOT
          INTO NAME,SURNAME,TOTAL
          FROM STATISTICS, PLAYERS, PERSON
          WHERE STATISTICS.SID=P_ID AND PERSON.ID=PLAYERS.SID AND      
          STATISTICS.PLAYERS_SID=PLAYERS.SID
        GROUP BY NAME,SURNAME;
END;

Select语句有效,但如何在Oracle中调用此过程?

我试过像

这样的东西
EXEC proc(4);

DECLARE
  NAME OUT CHAR,
  SURNAME OUT CHAR,
  TOTAL OUT CHAR

BEGIN
   P_ID := 12 ;
   proc (
   P_ID => P_ID,
   NAME => NAME,    
   SURNAME => SURNAME,
   TOTAL => TOTAL
);
END;

但没有任何成功。

1 个答案:

答案 0 :(得分:5)

  

EXEC proc(4);

EXECUTE SQL*Plus命令。

您有以下选项:

    SQL * Plus中的
  • EXECUTE
  • 在匿名 PL / SQL 块中调用
  • SQL Developer 客户端工具中
  • 运行

让我们看看以下三种方式:

SQL * Plus

SQL> variable v_ename varchar2(20);
SQL> exec get_emp(7788, :v_ename);

PL/SQL procedure successfully completed.

SQL> print v_ename;

V_ENAME
--------------------------------
SCOTT

匿名PL / SQL块

SQL> CREATE OR REPLACE PROCEDURE get_emp(
  2      i_empno IN emp.empno%TYPE,
  3      o_ename OUT emp.ename%TYPE)
  4  AS
  5  BEGIN
  6    SELECT ename INTO o_ename FROM emp WHERE empno = i_empno;
  7  END;
  8  /

Procedure created.

SQL> SET serveroutput ON
SQL> DECLARE
  2    v_ename VARCHAR2(20);
  3  BEGIN
  4    get_emp(7788, v_ename);
  5    dbms_output.put_line('Employee name is '||v_ename);
  6  END;
  7  /
Employee name is SCOTT

PL/SQL procedure successfully completed.

SQL Developer 客户端工具中:

  1. 转到左侧窗格中的连接
  2. 展开 程序
  3. enter image description here

    1. 右键点击,然后选择“运行”。
    2. enter image description here

      1. 它会打开一个新窗口,提供输入值,然后点击确定
      2. enter image description here

        1. 输出将在底部的输出日志中显示为“输出变量”。
        2. enter image description here