获取两个日期间的工作日,
SQL> select dt_time
2 from (select to_date('01-12-2010 08:20:56','dd-mm-yyyy HH:MI:SS') + level - 1 dt_time
3 from dual
4 connect by level <= sysdate - to_date('01-12-2010 08:20:56','dd-mm-yyyy HH:MI:SS') + 1
5 )
6 where to_char(dt_time,'d') not in ('1','7');
Oracle提供的层次查询(Hierarchical Queries)功能中的connect by子句可以协助我们便捷的达到目标。
1.创建测试表T
sec@ora10g> create table t (x int);
Table created.
2.使用“connect by level”完成插入1到10连续数字
sec@ora10g> insert into t select rownum from dual connect by level<=10;
10 rows created.