PL SQL 中声明时变量的默认值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1349936/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
default value of a variable at the time of declaration in PL SQL
提问by tuinstoel
What is the default value of a variable VARCHAR2
at the time of declaration in PL/SQL? Can I check it against NULL
once after I declare a variable?
VARCHAR2
PL/SQL 中声明时变量的默认值是多少?我可以NULL
在声明变量后检查一次吗?
回答by tuinstoel
Variables are default initialized with NULL.
变量默认初始化为 NULL。
You can change that, for example:
您可以更改它,例如:
create procedure show1
as
l_start varchar2(10) := 'Hello';
begin
if l_start is not null then
....
end if;
end;
/
You can also declare variables as not nullable:
您还可以将变量声明为不可为空:
create procedure show2
as
l_start varchar2(10) not null := 'Hello';
begin
null;
end;
/
回答by Andrew not the Saint
Defaults are NULL, you can use IS NULL or IS NOT NULL.
默认值为 NULL,您可以使用 IS NULL 或 IS NOT NULL。
回答by darreljnz
tuinstoel is correct.
tuinstoel 是正确的。
One addition: Don't be fooled into trying "ls_my_variable = NULL" as comparing with NULL always returns FALSE. Always use "ls_my_variable IS NULL" or "IS NOT NULL".
补充一点:不要被愚弄尝试“ls_my_variable = NULL”,因为与 NULL 比较总是返回 FALSE。始终使用“ls_my_variable IS NULL”或“IS NOT NULL”。
回答by Jim Hudson
And another small addition: if you're dealing with BLOBs (or CLOBS), "empty" is not the same as null. See the Oracle large objects manual if you need to.
还有一个小补充:如果您正在处理 BLOB(或 CLOBS),“空”与 null 不同。如果需要,请参阅 Oracle 大对象手册。