示例如下:
Create or replace function fn_TestDebug(p_Id number,P_Debug Boolean := False) return int
as
begin
return 1;
end; 调用1:
select fn_TestDebug(1) from dual; --成功
调用2:
declare
v_i int;
begin
v_i := fn_testDebug(1);
end;--成功调用3:
select fn_testDebug(1,true) from dual;--失败,将true换成false同样出现ORA-00904: "TRUE": 标识符无效
调用4:
declare
v_debug Boolean;
bein
v_debug := true;
select fn_testDebug(1,v_debug) from dual;
end;
失败,这次错的更离谱,如下:
ORA-06550: 第 5 行, 第 25 列:
PLS-00382: 表达式类型错误
ORA-06550: 第 5 行, 第 10 列:
PLS-00306: 调用 'FN_TESTDEBUG' 时参数个数或类型错误
ORA-06550: 第 5 行, 第 10 列:
PL/SQL: ORA-00904: "FN_TESTDEBUG": 标识符无效请各位大虾给个合理的解释...
Create or replace function fn_TestDebug(p_Id number,P_Debug Boolean := False) return int
as
begin
return 1;
end; 调用1:
select fn_TestDebug(1) from dual; --成功
调用2:
declare
v_i int;
begin
v_i := fn_testDebug(1);
end;--成功调用3:
select fn_testDebug(1,true) from dual;--失败,将true换成false同样出现ORA-00904: "TRUE": 标识符无效
调用4:
declare
v_debug Boolean;
bein
v_debug := true;
select fn_testDebug(1,v_debug) from dual;
end;
失败,这次错的更离谱,如下:
ORA-06550: 第 5 行, 第 25 列:
PLS-00382: 表达式类型错误
ORA-06550: 第 5 行, 第 10 列:
PLS-00306: 调用 'FN_TESTDEBUG' 时参数个数或类型错误
ORA-06550: 第 5 行, 第 10 列:
PL/SQL: ORA-00904: "FN_TESTDEBUG": 标识符无效请各位大虾给个合理的解释...
你这样定义,当然不对喽,ORACLE又不知道TRUE是其中一种类型
你就弄个NUMBER型号的,1代表TRUE,0 FALSE不就得了
给你举个例子:
OPER@tl>create or replace function f1(P_Debug Boolean := False)
2 return number
3 as
4 begin
5 if P_Debug=true then
6 return 1;
7 else
8 return 2;
9 end if;
10 end;
11 /函数已创建。OPER@tl>select f1 from dual; F1
----------
2OPER@tl>select f1(true) from dual;
select f1(true) from dual
*
第 1 行出现错误:
ORA-00904: "TRUE": 标识符无效
OPER@tl>select f1('true') from dual;
select f1('true') from dual
*
第 1 行出现错误:
ORA-06553: PLS-306: 调用 'F1' 时参数个数或类型错误
OPER@tl>var aaa number;
OPER@tl>exec :aaa:=f1(true)PL/SQL 过程已成功完成。OPER@tl>print aaa; AAA
----------
1
看看oracle的文档:
PL/SQL Boolean Types
PL/SQL has a type for representing Boolean values (true and false). Because SQL does not have an equivalent type, you can use BOOLEAN variables and parameters in PL/SQL contexts but not inside SQL statements or queries.BOOLEAN Datatype
You use the BOOLEAN datatype to store the logical values TRUE, FALSE, and NULL (which stands for a missing, unknown, or inapplicable value). Only logic operations are allowed on BOOLEAN variables.The BOOLEAN datatype takes no parameters. Only the values TRUE, FALSE, and NULL can be assigned to a BOOLEAN variable.You cannot insert the values TRUE and FALSE into a database column. You cannot select or fetch column values into a BOOLEAN variable. Functions called from a SQL query cannot take any BOOLEAN parameters. Neither can built-in SQL functions such as TO_CHAR; to represent BOOLEAN values in output, you must use IF-THEN or CASE constructs to translate BOOLEAN values into some other type, such as 0 or 1, 'Y' or 'N', 'true' or 'false', and so on.