Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Oracle-PLS-00382:表达式在减去日期时的类型错误_Oracle_Function_Date_Compiler Errors_Subtraction - Fatal编程技术网

Oracle-PLS-00382:表达式在减去日期时的类型错误

Oracle-PLS-00382:表达式在减去日期时的类型错误,oracle,function,date,compiler-errors,subtraction,Oracle,Function,Date,Compiler Errors,Subtraction,在Oracle中编译以下函数时遇到问题 CREATE OR REPLACE FUNCTION fn1 return binary_double as Fecha DATE; Dias binary_double; begin dbms_output.put_line(CAST(TRUNC(CURRENT_DATE,'DD') AS DATE) - cast(current_timestamp as date)); return Dias; end; 这会导致错误 Error(8,27): P

在Oracle中编译以下函数时遇到问题

CREATE OR REPLACE FUNCTION fn1
return binary_double
as
Fecha  DATE;
Dias binary_double;
begin
dbms_output.put_line(CAST(TRUNC(CURRENT_DATE,'DD') AS DATE) - cast(current_timestamp as date));
return Dias;
end;
这会导致错误

Error(8,27): PLS-00382: expression is of wrong type
但是,在函数体之外运行相同的表达式

select CAST(TRUNC(CURRENT_DATE,'DD') AS DATE) - cast(current_timestamp as date) from dual
给出预期结果-两个日期之间的天数

-0.0607060185185185185185185185185185185185
对于该功能可能出现的错误有什么看法吗?

使用:

begin
  dbms_output.put_line(TRUNC(CURRENT_DATE,'DD')  - cast( current_timestamp as date));
end;
/
当前日期返回数据类型日期的值
Trunct还返回日期。
因此,您正在尝试将日期类型转换为日期类型。

使用:

begin
  dbms_output.put_line(TRUNC(CURRENT_DATE,'DD')  - cast( current_timestamp as date));
end;
/
当前日期返回数据类型日期的值
Trunct还返回日期。

因此,您正在尝试将日期类型转换为日期类型。

似乎PL/SQL对转换为相同类型的类型有问题

CURRENT_DATE
返回
DATE
数据类型,因此您可以将其转换为相同的类型。它可以在SQL中工作,但不能在PL/SQL中工作。只需拆下铸件:

CREATE OR REPLACE FUNCTION fn1
return binary_double
as
Fecha  DATE;
Dias binary_double;
begin
dbms_output.put_line(TRUNC(CURRENT_DATE,'DD') - cast(current_timestamp as date));
return Dias;
end;

似乎PL/SQL对于转换为相同类型的类型有问题

CURRENT_DATE
返回
DATE
数据类型,因此您可以将其转换为相同的类型。它可以在SQL中工作,但不能在PL/SQL中工作。只需拆下铸件:

CREATE OR REPLACE FUNCTION fn1
return binary_double
as
Fecha  DATE;
Dias binary_double;
begin
dbms_output.put_line(TRUNC(CURRENT_DATE,'DD') - cast(current_timestamp as date));
return Dias;
end;