Oracle View Build Date

本文介绍了一种在Oracle数据库中生成指定日期范围内的所有日期的方法。通过定义类型和函数,可以创建一个包含从起始日期到结束日期的所有日期的表。这种方法适用于需要在查询中使用连续日期序列的场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Ref:http://www.adp-gmbh.ch/ora/sql/table_cast.html
 
 
 
create or replace type date_obj as object (dt date)
/

create or replace type date_table as table of date_obj
/


create or replace function date_range(from_dt in date, to_dt in date) 
  return date_table as
    a_date_table date_table := date_table();
    cur_dt date:=from_dt;
  begin
    while cur_dt <= to_dt loop
      a_date_table.extend;
      a_date_table(a_date_table.count) := date_obj(cur_dt);
      cur_dt := cur_dt + 1;
    end loop;
  return a_date_table;
end date_range;
/
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
select * from  table (
cast ( date_range(
    to_date('01.01.2002','dd.mm.yyyy'),
    to_date('31.01.2002','dd.mm.yyyy')
  ) 
as date_table
));

转载于:https://www.cnblogs.com/kevinkim/archive/2012/02/22/2363307.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值