简体   繁体   中英

wrong number or types of arguments in call (while calling a procedure/function)

If I want to catch this error using exception handling, what are the things that I need to take care of?

wrong number or types of arguments in call (while calling a procedure/function)

I trying was in different way. Could you please explain. I have a function:

create or replace function test5(v varchar2) return varchar as
begin
  execute immediate 'begin sweet.g:=:v;end;'
  using in v;
  return sweet.g;
exception
when others then 
  return sqlcode||' '||sqlerrm;
end test5;

And a package spec and body:

create or replace package SWEET as
  function c ( v varchar2,V2 VARCHAR2) return varchar2;
  g varchar(100);
end;
/

create or replace package body SWEET as
  function c(v varchar2, V2 varchar2) return varchar2 as
  begin
    return v||'hi'|| V2;
  end c;
end; 
/

when I execute the statement below, I was not able to catch 'wrong number or type of arguments'

select test5(sweet.c(,'hello')) from dual;

You should be able to get most of the answers in the PL/SQL manual, but when you are trying to trap an error that isn't one of the predefined ones you have to do something like:

DECLARE
   deadlock_detected EXCEPTION;
   PRAGMA EXCEPTION_INIT(deadlock_detected, -60);
BEGIN
   ... -- Some operation that causes an ORA-00060 error
EXCEPTION
   WHEN deadlock_detected THEN
      -- handle the error
END;

replacing -60 with your actual error, and deadlock_detected with whatever you wish to call it.

Let's say you have a procedure that takes in two numbers as arguments and outputs them:

create procedure testProc (p_param1 in number, p_param2 in number) is
begin
  dbms_output.put_line('params: ' || p_param1 || ' ' || p_param2);
end;

If you execute this:

begin
  testProc(13,188);
end;

You get output of: params: 13 188

If you do this:

begin
  testProc(13);
exception when others then
  dbms_output.put_line('SQLERRM: ' || SQLERRM);
end;

You get an error: PLS-00306: wrong number or types of arguments in call to 'TESTPROC'

To prevent this and catch the error, you can use dynamic SQL:

declare
  v_sql varchar2(50);
  v_result number;
begin
  v_sql := 'begin testProc(13); end;';
  execute immediate v_sql into v_result;
exception
when others then
  dbms_output.put_line('SQLERRM: ' || SQLERRM);
end;

That will execute, and the error message will be displayed to dbms_output. In the when others then block you can write any logic you want for what should happen at that point.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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