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

发布于 2024-09-25 02:51:12 字数 446 浏览 2 评论 0原文

如何在此过程中应用 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;

How do I apply IN parameter as my_email and OUT as my_salary in this procedure:

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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

挽清梦 2024-10-02 02:51:12

您无法将值返回到 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;
/

You can't return a value into an IN parameter. What I suspect you want is a general purpose procedure like this:

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;
/

... which you can then call like this:

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;
/
忆沫 2024-10-02 02:51:12

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

DECLARE   
    salary employees.salary%TYPE;    
BEGIN    
    FYI_CENTER('[email protected]', salary);    
END;

You set the IN parameter and add the OUT parameter as a variable like this:

DECLARE   
    salary employees.salary%TYPE;    
BEGIN    
    FYI_CENTER('[email protected]', salary);    
END;
眼眸里的那抹悲凉 2024-10-02 02:51:12

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'),只是通用格式类型。

正如托尼指出的,您可以将过程声明为:

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
...

IN and OUT relative to what? Neither is a parameter at the moment. It looks more like you want both of those to be OUT parameters, and the employee ID to be an IN parameter, something like:

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;

... which you call call something like:

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;

You can't specify the exact format of the input and output variables (`%TYPE') in a procedure, just the generic format type.

As Tony pointed out, you could declare the procedure as:

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
...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文