简体   繁体   English

运行存储过程时出错

[英]Getting error while running a Stored Procedure

Table structure 表结构

Name     Null Type         
-------- ---- ------------ 
EMP_NO        NUMBER       
EMP_NAME      VARCHAR2(30) 
ADDRESS       VARCHAR2(15) 
PH_NO         NUMBER(10)   
DPT_NO        NUMBER       

Procedure 程序

create or replace procedure procedure1 (nom in employees.emp_no%type,
                                      vemp_name out employees.emp_name%type)
is                               
begin
    select emp_name into vemp_name from employees where emp_no=nom; 
end;

Call 呼叫

exec procedure1(1);

It is showing error like 它显示错误

Error 错误

PLS-00306: wrong number or types of arguments in call to 'PROCEDURE1'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:

I don't know why it is showing that error. 我不知道为什么会出现这个错误。 Please suggest me. 请建议我。

The error message is easy enough to understand. 错误消息很容易理解。 It's simple maths. 这是简单的数学。 Your procedure has two parameters; 你的程序有两个参数; your call only passes one . 你的电话只通过一个

To resolve this you need to pass a variable to receive the out parameter: 要解决此问题,您需要传递一个变量来接收out参数:

var n varchar2(30)   

exec procedure1(1, :n)

print n

Note the colon we need to use when referencing the SQL*Plus variable in SQL or PL/SQL. 注意在SQL或PL / SQL中引用SQL * Plus变量时我们需要使用的冒号。


"after executing ur code am getting error Error report:" “执行你的代码后得到错误错误报告:”

Hmmm, either you are not executing my code or your code doesn't match what you have posted in your question. 嗯,要么您没有执行我的代码,要么您的代码与您在问题中发布的代码不符。

Here is your table as presented... 这是你提出的表...

SQL> create table employees ( 
  2    EMP_NO        NUMBER       
  3    ,EMP_NAME      VARCHAR2(30) 
  4    ,ADDRESS       VARCHAR2(15) 
  5    ,PH_NO         NUMBER(10)   
  6    ,DPT_NO        NUMBER )
  7    ;

Table created.

SQL> insert into employees values (1, 'MR KNOX', 'LONDON', 23, 10)
   2 /

1 row created.


SQL> insert into employees values (2, 'FOX IN SOX', 'BOSTON', 42, 20)
   2 /

1 row created.

SQL>

Here is your procedure as presented .... 这是你提出的程序....

SQL> create or replace procedure procedure1 (nom in employees.emp_no%type,
   2                                      vemp_name out employees.emp_name%type)
   3 is                               
   4 begin
   5    select emp_name into vemp_name from employees where emp_no=nom; 
   6 end;  
   7  /

Procedure created.

SQL>

Here is my demonstration of how to call it: 这是我演示如何调用它:

SQL> var n varchar2(30)   

SQL> exec procedure1(1, :n)

PL/SQL procedure successfully completed.

SQL>  print n
N
--------------------------------------------------------------------------------
MR KNOX

SQL> exec procedure1(2, :n)

PL/SQL procedure successfully completed.

SQL>  print n


N
--------------------------------------------------------------------------------
FOX IN SOX

SQL> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM