如何在此程序中应用参数?

时间:2010-09-26 06:37:32

标签: oracle plsql

如何在此过程中将IN参数应用为my_email,将OUT应用为my_salary:

CREATE OR REPLACE PROCEDURE FYI_CENTER AS
  my_email employees.email%TYPE;    -- **IN Parameter**
  my_salary employees.salary%TYPE;  -- **OUT Parameter**

BEGIN

  SELECT email, salary INTO my_email, my_salary
    FROM employees WHERE employee_id = 101;

  DBMS_OUTPUT.PUT_LINE('My email = ' || my_email);
  DBMS_OUTPUT.PUT_LINE('My salary = ' || my_salary);
END;

3 个答案:

答案 0 :(得分:4)

您无法将值返回到IN参数中。我怀疑你想要的是这样的通用程序:

CREATE OR REPLACE PROCEDURE FYI_CENTER 
  ( p_employee_id IN employees.employee_id%TYPE
  , p_email OUT employees.email%TYPE
  , p_salary OUT employees.salary%TYPE
  )
AS
BEGIN

  SELECT email, salary INTO p_email, p_salary
    FROM employees WHERE employee_id = p_employee_id;

END;
/

...然后您可以这样调用:

DECLARE
  my_email employees.email%TYPE;    -- **IN Parameter**
  my_salary employees.salary%TYPE;  -- **OUT Parameter**
BEGIN
  fyi_center (101, my_email, my_salary);
  DBMS_OUTPUT.PUT_LINE('My email = ' || my_email);
  DBMS_OUTPUT.PUT_LINE('My salary = ' || my_salary);
END;
/

答案 1 :(得分:0)

设置IN参数并将OUT参数添加为变量,如下所示:

DECLARE   
    salary employees.salary%TYPE;    
BEGIN    
    FYI_CENTER('jonhdoe@email.com', salary);    
END;

答案 2 :(得分:0)

IN和OUT相对于什么?目前也不是参数。它看起来更像是你想要两个都是OUT参数,而员工ID是一个IN参数,如:

CREATE OR REPLACE PROCEDURE FYI_CENTER(my_id IN number, my_email OUT varchar2,
    my_salary OUT varchar2) AS
BEGIN
    SELECT email, salary INTO my_email, my_salary
    FROM employees WHERE employee_id = my_id;
END;

...你称之为:

DECLARE
    my_email employees.email%TYPE;
    my_salary employees.salary%TYPE;
BEGIN
    FYI_CENTER(101, my_email, my_salary);

    DBMS_OUTPUT.PUT_LINE('My email = ' || my_email);
    DBMS_OUTPUT.PUT_LINE('My salary = ' || my_salary);
END;

您不能在过程中指定输入和输出变量('%TYPE')的确切格式,只能指定通用格式类型。

正如Tony指出的那样,你可以将程序声明为:

CREATE OR REPLACE PROCEDURE FYI_CENTER(my_id IN employees.employee_id%TYPE,
    my_email OUT employees.email%TYPE
    my_salary OUT employees.salary%TYPE) AS
BEGIN
...