user2854207
user2854207

Reputation:

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.

Upvotes: 1

Views: 1726

Answers (1)

APC
APC

Reputation: 146179

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:

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.


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

Upvotes: 3

Related Questions