gpt4 book ai didi

oracle - Oracle运算符<>在varchar2中不起作用

转载 作者:行者123 更新时间:2023-12-04 01:51:17 26 4
gpt4 key购买 nike

我已创建表TEST,供数据库Oralce中的运算符<>使用。
当您运行以下命令时,我发现奇怪的是未返回任何记录。

为什么不返回任何记录?在SQL Server和Firebird数据库中,该命令有效。

无法运作的SQL

select * from TEST where Adress <> '';


http://sqlfiddle.com/#!4/7e89f/2

create table TEST(
ID int not null,
Name varchar2(100) not null,
Adress varchar2(100)
);

alter table TEST add constraint TEST_pk primary key (ID);

insert into TEST values (1, 'Emily', null);
insert into TEST values (2, 'Michael', 'Test');
insert into TEST values (3, 'Daniel', 'Test');
insert into TEST values (4, 'Alexis', 'Test');

最佳答案

甲骨文著名的treats an empty string as null

您所做的与:

select * from TEST where Adress <> null;


...以及与空 is undefined相比的任何结果。

您必须使用空比较运算符:

select * from TEST where Adress is not null;


Read more about Oracle's handling of nulls

关于oracle - Oracle运算符<>在varchar2中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40307901/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com