我想检查一个变量是否无效。 如果无效,我就想对这一变量设定一个价值:
//data type of var is number
if Var = null then
var :=5;
endif
但我却在错了。 我如何检查变数是否无效?
我正在使用矿石数据类型
我想检查一个变量是否无效。 如果无效,我就想对这一变量设定一个价值:
//data type of var is number
if Var = null then
var :=5;
endif
但我却在错了。 我如何检查变数是否无效?
我正在使用矿石数据类型
if var is NULL then
var :=5;
end if;
在PL/SQL中,由于与<代码>NUL的所有比较,你可以提用操作员,如 = 或lt;> 测试。 比较<代码>NUL上的部分,您需要使用特殊操作者IS NUL
或,这些特别操作者正是为此目的使用的。 因此,而不是书面
IF var = NULL THEN...
页: 1
IF VAR IS NULL THEN...
如果是的话,请你选择使用<代码>NVL。 NUL
,则将第二个论点退回。 如果第1条关于NUL
,第1条理由即告回。 因此,你可以改写
IF var IS NULL THEN
var := 5;
END IF;
页: 1
var := NVL(var, 5);
我希望这一帮助。
既然我写了这一答案已有将近10年,那么,仅扩大这个答案就值得庆贺。
<编码>COALESCE功能是Oracle s 代码
It takes any number of arguments, and returns the first one which is not NULL. If all the arguments p页: 1sed to COALESCE
are NULL, it returns NULL.
In contr页: 1t to NVL
, COALESCE
only evaluates arguments if it must, while NVL
evaluates both of its arguments and then determines if the first one is NULL, etc. So COALESCE
can be more efficient, because it doesn t spend time evaluating things which won t be used (and which can potentially cause unwanted side effects), but it also means that COALESCE
is not a 100% straightforward drop-in replacement for NVL
.
如果使用无效
永远不会比任何东西都大、小、平等或不平等。 避免这种情况的最佳办法是使用Nvl。
例如
declare
i integer;
begin
if i <> 1 then
i:=1;
foobar();
end if;
end;
/
该条款从未在其中。
这将发挥作用。
if 1<>nvl(i,1) then
if i<> 1 or i is null then
另一种方式:
var := coalesce (var, 5);
COALESCE是Oracle s NVL(多或少)功能的ANSI当量。
I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...
I ve got the following objects: CREATE FUNCTION CONSTFUNC RETURN INT DETERMINISTIC AS BEGIN RETURN 1; END; CREATE TABLE "FUNCTABLE" ( "ID" NUMBER(*,0) NOT NULL, "VIRT" NUMBER GENERATED ALWAYS AS ...
The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...
I was wondering, is there a way to make a kind of one to one left outer join: I need a join that matches say table A with table B, for each record on table A it must search for its pair on table B, ...
I need to be able to run an Oracle query which goes to insert a number of rows, but it also checks to see if a primary key exists and if it does, then it skips that insert. Something like: INSERT ALL ...
I just came across NULL values in NOT-NULL fields in our test database. How could they get there? I know that NOT-NULL constraints can be altered with NOVALIDATE clause, but that would change table s ...
I m studying databases and am currently working on a object-relational DB project and I ve encountered a small problem with the number of possible constraints in an object table. I m using "Database ...
we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...