范围比较
数字和字符串比较
字符串被转为double
SELECT i FROM t WHERE i <= all {'11','12'};
i
=============
1
2
3
4
字符串和日期时间比较
字符串转为日期或时间
SELECT s FROM t2;
s
======================
'01/01/2000'
'01/01/1999'
'01/01/1998'
SELECT s FROM t2 WHERE s <= ALL {date'02/02/1998',date'01/01/2000'};
s
======================
'01/01/1998'
报错了
计算比较
Date/Time Type Operand
如果日期是间操作是-操作. 返回的是毫秒
SELECT date'2002-01-01' - datetime'2001-02-02 12:00:00 am';
date '2002-01-01'- datetime '2001-02-02 12:00:00 am'
=====================================================
28771200000
同类型比较看优先级
Date/Time Type & String Type Operands
如果有+-操作的话 结果如下
DATE: 返回天
TIME, TIMESTAMP:返回 秒
DATETIME:返回 毫秒
SELECT date'2002-01-01' + '10';
date '2002-01-01'+'10'
======================
01/11/2002
SELECT date'2002-01-01'-'2001-01-01';
date '2002-01-01'-'2001-01-01'
================================
31536000000
-- 下面的操作是不可以的
SELECT date'2002-01-01'-'10';
In line 1, column 13,
ERROR: 10不是日期类型.
Numeric Type & String Type Operands
SELECT 4 + '5.2';
4+'5.2'
==========================
9.199999999999999e+00
SELECT '2002-01-01'+1;
ERROR: 不能把'2002-01-01'转为double类型
SELECT DATE'2002-01-01'+1;
date '2002-01-01'+1
=====================
01/02/2002
String Type Operand
字符串的乘除操作返回double类型
SELECT '3'*'2';
'3'*'2'
============================
6.000000000000000e+00
字符串的加操作为连接操作. ( 具体跟对加号的意义的配置有关 plus_as_concat 在 cubrid.conf中 )
- SELECT '1'+'1';
- '1'+'1'
- ======================
- '11'
- 如果plus_as_concat 没设置则
- '1'+'1'
- ==========================
- 2.000000000000000e+00
An error will be returned if it cannot be converted to the corresponding type.