db2中也有一个类似于oracle中的dual表的系统表是:sysibm.sysdummy1
功能也类似,例如:
select current date from sysibm.sysdummy1
select current timestamp from sysibm.sysdummy1
select 100 as value1 from sysibm.sysdummy1
——————————————————————————————————————————————
习惯了使用dual或者表名难记,可以建立一个视图方便查询系统数据:
create view dual as select IBMREQD as DUMMY from SYSIBM.SYSDUMMY1
应用举例:
select current timestamp from dual
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') as nowTime from dual;
select to_char(sysdate,'yyyy') as nowYear from dual; //获取时间的年
select to_char(sysdate,'mm') as nowMonth from dual; //获取时间的月
select to_char(sysdate,'dd') as nowDay from dual; //获取时间的日
select to_char(sysdate,'hh24') as nowHour from dual; //获取时间的时
select to_char(sysdate,'mi') as nowMinute from dual; //获取时间的分
select to_char(sysdate,'ss') as nowSecond from dual; //获取时间的秒
延伸阅读:
http://blog.csdn.net/lpioneer/article/details/5940366
http://blog.csdn.net/dada360778512/article/details/6170580