Lightdb数据库——where in条件查询功能增强

where in查询的语法示意图

如上图所示,在原始的在where in查询中,in后续的差选必须带有括号,否则无法查询。

本次对In条件查询功能进行增强:

①子查询、多元素链表必须待括号;

②单个元素查询可以不带括号,直接查询,例子如下:

支持类型和用例

目前In后查询不加括号的有:数值类型单个元素、字符串类型单个元素、函数、数值加减运算、函数加减运算等。

以下案例参考的表结构如下:

create table test (

a int,

b varchar(100),

c varchar2(10),

d date,

m timestamp(6),

n ROWID

);

数值

select * from test where a in 2;

字符串

select * from test where b in 'abc';

select * from test where c in 'abc';

日期

select * from test where d in to_date('2022-01-01','yyyy-mm-dd');

select * from test where m in to_timestamp('2022-01-01','yyyy-mm-dd');

Rowid类型

select * from test where n in '(0,1)'::tid;

加减运算

1.数值类型的加减运算:

select * from test where a in 2+1;

select * from test where a in 2-1;

select * from test where a in 2*1;

select * from test where a in 2/1;

2.表的列名的加减运算

select * from test t where a in t.a/1;

select * from test t where a in t.a+1;

select * from test t where a in t.a-1;

select * from test t where a in t.a*1;

select * from test t where a in t.a/1;

select * from test t where a in t.a+t.a;

select * from test t where a in t.a-t.a;

select * from test t where a in t.a*t.a;

3.函数加减运算

select a from test where a in TO_NUMBER(2)+2;

select a from test where a in TO_NUMBER(2)+ TO_NUMBER(2)

函数

SELECT * FROM test WHERE a IN CAST ('1' AS INTEGER);

select * from test where a in TO_NUMBER(2);

select * from test where  m in TIMESTAMP '2022-01-01 00:00:00' AT TIME ZONE 'Asia/Shanghai';

 支持右括号和无括号混合使用

select * from test where a in

  (select a from test where a in TO_NUMBER(2)+2 and 

   b in (select b from test where b in 'test' and b is not null) and

   c in  (select  c from test where c in 'cf' and c like 'c%')and

   d in  to_date('2022-01-01','yyyy-mm-dd') and

   m in TIMESTAMP '2022-01-01' AT TIME ZONE 'Asia/Shanghai' ) ;

  • 21
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值