PLS-00382:表达式的类型错误.PL/SQL:已忽略语句



我尝试执行一个带有函数重载的简单包。下面是程序包代码。

--package specification:
create or replace package over_load as
FUNCTION print_it(v_date date) return date;
FUNCTION print_it(v_name varchar2) return number;
end over_load;
--package body:
create or replace package body over_load as
FUNCTION print_it(v_date date) return date is --function accepting and returning date
begin
dbms_output.put_line('the date is ' || v_date);
return v_date;
end print_it;
FUNCTION print_it(v_name varchar2) return number is /*function accepting string and returning number*/
v_eno employees.employee_id%type;
begin
select employee_id into v_eno from employees where first_name = v_name;
return v_eno;
end print_it;
end over_load;

我尝试使用下面的匿名块执行包中的第一个函数。

declare
sample_date date;
begin
sample_date := over_load.print_it('14-07-2017');
dbms_output.put_line(sample_date);
end;

我尝试将date作为参数传递给第一个函数,但它抛出了错误的参数类型错误。知道为什么吗?

如果过程(或函数(需要DATE数据类型,则不要将字符串传递给它。因为'14-07-2017'是一个字符串。

SQL> set serveroutput on
SQL>
SQL> declare
2    sample_date date;
3  begin
4    --sample_date := over_load.print_it('14-07-2017');
5    sample_date := over_load.print_it(date '2017-07-14');
6    dbms_output.put_line(sample_date);
7  end;
8  /
the date is 14.07.17
14.07.17
PL/SQL procedure successfully completed.
SQL>

在第5行中,我传递了一个日期文字。也可能是to_date('14-07-2017', 'dd-mm-yyyy')

Oracle(如果可以的话(隐式地将您传递的数据转换为它期望的数据类型,但它并不总是成功;这取决于NLS设置。

为了确保它始终有效,请控制它并使用适当的数据类型。

最新更新