下列查询两个expression列中对call_time和res_dtime列返回日期(一个月中的某一天)
select customer_num,DAY(call_time),DAY(res_dtime) from cust_calls;
查询结果如下:
customer_num expression expression
106 12 12
110 7 7
116 28 28
下列查询使用DAY和CURRENT函数来将列值与当前日期进行比较。它只选择值比当前日期早的那些行。在此例中,CURRENT日是15。
select customer_num,DAY(call_time),DAY(res_dtime) from cust_calls where DAY(call_time)
查询结果如下:
customer_num expression expression
106 12 12
110 7 7
SYSDATE函数与CURRENT函数及其类似,但当未指定DATETIME限定符时,其返回值的缺省精度是DATETIME YEAR TO FRACTION(5),而不是CURRENT的缺省精度DATETIME YEAR TO FRACTION(3)。
下列查询使用MONTH函数来抽取和显示在哪个月份接收和处理客户来电,并且将对结果使用显示标签。但是,它不区分年份。
select customer_num,MONTH(call_time) call_month,MONTH(res_dtime) res_month from cust_calls;
查询结果如下:
customer_num call_month res_month
106 6 6
110 7 7
如果DAY比当前日期早,那么下列查询使用MONTH函数和DAY及CURRENT来显示哪个月份接收和处理客户来电。
select customer_num,MONTH(call_time) call_month,MONTH(res_dtime) res_month from cust_calls where DAY(call_time)
查询结果如下:
customer_num call_month res_month
106 6 6
110 7 7
下列查询使用WEEKDAY函数来指示在星期几接收并处理来电(0表示星期日,1表示星期一,以此类推),并标记表达式列。
select customer_num,WEEKDAY(call_time) called,WEEKDAY(res_dtime) resolved from cust_calls order by resolved ;
查询结果如下:
customer_num called resolved
127 3 6
110 0 0
下列查询使用COUNT和WEEKDAY函数来对在周末收到的来电进行计数。
select count(*) from cust_calls where WEEKDAY(call_time) in (0,6);
查询结果如下:
(count(*))
4
下列查询检索call_time比当前年份的开始早的行。
select customer_num,YEAR(call_time) call_year,YEAR(res_dtime) res_year from cust_calls where YEAR(call_time)
查询结果如下:
customer_num call_year res_year
116 1997 1997
除了以上示例说明的内置时间函数之外,GBase 8s还支持ADD_MONTH,LAST_DAY,MDY,MONTHS_BETWEEN,NEXT_DAY和QUARTER函数。除了这些函数,TRUNC和ROUND函数也可返回更改DATE和DATETIME参数精度的值。