CREATE OR REPLACE Package Pkg_Stm_Date As
    --Purpose:相关日期处理功能包
    
    --获取某一天是第几周
    Function Fn_GetWeekbyDate(P_Date Varchar2) Return Varchar2;     --获取某一天是第几周
    Function Fn_GetWeekbyDate(P_Date Date) Return Varchar2;     --获取某一天是周几
    Function Fn_GetWeekDaybyDate(P_Date Varchar2) Return Varchar2;     --获取某一天是周几
    Function Fn_GetWeekDaybyDate(P_Date Date) Return Varchar2;
    
    --获取该日期所在的周是单周还是双周
    Function Fn_GetWeekTypeByDate(P_Date Varchar2) Return Pls_Integer;
    
    --根据查询日期,获取该日期所在的星期的星期一对应的日期
    Function Fn_GetMonDayByDate(P_Date Varchar2) Return Varchar2;   
   
    --获取连续的日期列表,返回游标类型
    Function Fn_GetDateList(P_StartDate Varchar2, P_EndDate Varchar2) Return Sys_refcursor;
   
    --获取连续的日期列表,返回结果集
    Function Fn_GetDateTable(P_StartDate Varchar2, P_EndDate Varchar2) Return TblTyp_Var Pipelined;
   
    --获取当天日期
    Function Fn_GetCurrentDate Return Varchar2;
    
    --获取当前日期和时间
    Function Fn_GetCurrentDateTime Return Varchar2;
    
    --获取数字型当前日期和时间
    Function Fn_GetNumbericCurrentDateTime Return Varchar2;
      
    --获取当年的第一天
    Function Fn_GetCurrentYearStartDate Return Varchar2;
   
    --获取当年的最后一天
    Function Fn_GetCurrentYearEndDate    Return Varchar2;
    
    --获取当前时间
    Function Fn_GetCurrentTime Return Varchar2;
End Pkg_Stm_Date; CREATE OR REPLACE Package Body Pkg_Stm_Date As
--Author:chenqingchang
--Purpose:相关日期处理功能包 --获取某一天是第几周
Function Fn_GetWeekbyDate(P_Date Varchar2) Return Varchar2
Is
Begin
Return To_char(To_Date(P_Date,'yyyy-mm-dd'),'fmiw');
End Fn_GetWeekbyDate; --获取某一天是第几周
Function Fn_GetWeekbyDate(P_Date Date) Return Varchar2
Is
Begin
Return To_Char(P_Date,'fmiw');
End Fn_GetWeekbyDate; --获取某一天是周几
Function Fn_GetWeekDaybyDate(P_Date Varchar2) Return Varchar2
Is
Begin
Return to_char(To_Date(P_Date,'yyyy-mm-dd'),'day','nls_date_language=''simplified chinese''');
End Fn_GetWeekDaybyDate; --获取某一天是周几
Function Fn_GetWeekDaybyDate(P_Date Date) Return Varchar2
Is
Begin
Return to_char(P_Date,'day','nls_date_language=''simplified chinese''');
End Fn_GetWeekDaybyDate; --获取该日期所在的周是单周还是双周
Function Fn_GetWeekTypeByDate(P_Date Varchar2) Return Pls_Integer
Is
Begin
Return Mod(Pkg_Stm_Date.Fn_GetWeekbyDate(P_Date), 2);
End Fn_GetWeekTypeByDate; --根据查询日期,获取该日期所在的星期的星期一对应的日期
Function Fn_GetMonDayByDate(P_Date Varchar2) Return Varchar2
Is
L_MonDayByDate Varchar2(19);
Begin
Select to_char(trunc(to_date(P_Date,'yyyy-mm-dd'),'iw') ,'yyyy-mm-dd')
Into
L_MonDayByDate
From dual; Return L_MonDayByDate;
End Fn_GetMonDayByDate; --获取日期列表,返回游标类型
Function Fn_GetDateList(P_StartDate Varchar2, P_EndDate Varchar2) Return Sys_refcursor
Is
L_CurDate Sys_refcursor; Begin
Open L_CurDate For
Select TO_DATE(P_StartDate, 'YYYY-MM-DD') + NUMTODSINTERVAL(Level, 'day') thisDate
From dual
Connect By Level <= To_Date(P_EndDate,'yyyy-mm-dd') - To_Date(P_StartDate, 'yyyy-mm-dd'); Return L_CurDate;
End Fn_GetDateList; --返回日期列表,以表数据方式显示可以进行表关联
Function Fn_GetDateTable(P_StartDate Varchar2, P_EndDate Varchar2) Return TblTyp_Var Pipelined
Is
L_StartDate Varchar2(20) := '';
Begin
Select to_Char(to_Date(P_StartDate,'yyyy-mm-dd') - 1,'yyyy-mm-dd')
Into L_StartDate
From dual; For dateRow In
(
Select TO_DATE(L_StartDate, 'yyyy-mm-dd') + NUMTODSINTERVAL(Level, 'day') thisDate
From dual
Connect By Level <= To_Date(P_EndDate,'yyyy-mm-dd') - To_Date(L_StartDate, 'yyyy-mm-dd')
) loop
Pipe Row(to_char(dateRow.thisDate,'yyyy-mm-dd'));
End Loop; Return;
End Fn_GetDateTable; --获取当天日期
Function Fn_GetCurrentDate Return Varchar2
Is
L_CurrentDate Varchar2(19);
Begin
Select to_char(SysDate,'yyyy-MM-dd')
Into L_CurrentDate
From dual; Return L_CurrentDate;
End Fn_GetCurrentDate; --获取当前日期和时间
Function Fn_GetCurrentDateTime Return Varchar2
Is
Begin
Return To_Char(SysDate, 'yyyy-mm-dd hh:mm:dd');
End Fn_GetCurrentDateTime; --生成数字型的当前日期和时间
Function Fn_GetNumbericCurrentDateTime Return Varchar2
Is
Begin
Return Replace(Replace(Pkg_Stm_Date.Fn_GetCurrentDateTime(),'-', ''),':', '');
End Fn_GetNumbericCurrentDateTime; --获取当年的第一天
Function Fn_GetCurrentYearStartDate Return Varchar2
Is
L_CurrentYearStartDate Varchar2(19);
Begin
Select to_Char(trunc(SysDate,'yyyy'),'yyyy-mm-dd')
Into L_CurrentYearStartDate
From dual; Return L_CurrentYearStartDate;
End Fn_GetCurrentYearStartDate; --获取当年的最后一天
Function Fn_GetCurrentYearEndDate Return Varchar2
Is
L_CurrentYearEndDate Varchar2(19);
Begin
Select to_char(add_months(trunc(sysdate,'yyyy'),12) - 1,'yyyy-mm-dd')
Into L_CurrentYearEndDate
From dual; Return L_CurrentYearEndDate;
End Fn_GetCurrentYearEndDate; --获取当前时间
Function Fn_GetCurrentTime Return Varchar2
Is
Begin
Return To_Char(SysDate,'HH24:MI:SS');
End Fn_GetCurrentTime; End Pkg_Stm_Date;

Oracler读取各种格式的相关日期格式的更多相关文章

  1. eclipse/MyEclipse 日期格式、注释日期格式、时区问题

    eclipse/MyEclipse 日期格式.注释日期格式.时区问题 在eclipse/MyEclipse中,如果你的注释或是运行System.out.print(new java.util.Date ...

  2. js 将long日期格式 转换为标准日期格式方法

    我们经常在操作的时候会发现从后台传递到view层的json中datetime类型变成了long型,当然你也可以从后台先转为string类型,但是如果是从和数据库对应的object中封装的话,就不能再去 ...

  3. oracle日期格式和java日期格式区别 HH24:mm:ss和HH24:mi:ss的区别

    转载自:https://blog.csdn.net/yubin_yubin/article/details/18655553 在日期数据库数据查询出来的时候经常会to_char()一下,格式化一下日期 ...

  4. 给Nginx配置日志格式和调整日期格式

    效果对比 官方默认日志格式 # 官方默认日志格式 log_format main '$server_name $remote_addr - $remote_user [$time_local] &qu ...

  5. java读取excel或者csv时日期格式数据处理

    背景:最近写一个通过excel批量导入数据的功能,里面含有时间,但是java读取之后把时间转为了距离1990年1月1号的天数,比如excel中时间为2018/9/16 18:30,java读取之后变成 ...

  6. C# 读取Excel 单元格是日期格式

    原文地址:https://www.cnblogs.com/liu-xia/p/5230768.html DateTime.FromOADate(double.Parse(range.Value2.To ...

  7. js/ts/tsx读取excel表格中的日期格式转换

    const formatDate = (timestamp: number) => { const time = new Date((timestamp - 1) * 24 * 3600000 ...

  8. js将long日期格式转换为标准日期格式

    <script language="javascript"> //扩展Date的format方法 Date.prototype.format = function (f ...

  9. eclipse/MyEclipse 日期格式、注释日期格式、时区问题[转]

    http://www.cnblogs.com/hoojo/archive/2011/03/21/1990070.html 在eclipse/MyEclipse中,如果你的注释或是运行System.ou ...

随机推荐

  1. 第三方:GDataXMLNode:xml解析库--备用

    一.GDataXMLNode说明   GDataXMLNode是Google提供的用于XML数据处理的类集.该类集对libxml2--DOM处理方式进行了封装,能对较小或中等的xml文档进行读写操作且 ...

  2. 最常用的动态sql语句梳理——分享给使用Mybatis的小伙伴们!

    公司项目中一直使用Mybatis作为持久层框架,自然,动态sql写得也比较多了,最常见的莫过于在查询语句中使用if标签来动态地改变过滤条件了.Mybatis的强大特性之一便是它的动态sql,免除了拼接 ...

  3. Hive的MoveTask错误

    最近在部署Hive上线,结果在线上线下同时出现了MoveTask报错的现象,虽然两者错误的日志以及错误信息一样,但是经过分析解决又发现两者的原因是不一样的. 首先线下的错误日志: 2015-05-18 ...

  4. css filter详解

    css filter详解 filter 属性详解 属性 名称 类型 说明 grayscale 灰度 值为数值 取值范围从0到1的小数(包括0和1) sepia 褐色 值为数值 取值范围从0到1的小数( ...

  5. 日期相关---SimpleDateFormat的setLenient(true/false)-----自动计算日期

    有时候我们需要判断用户的日期格式是否正确, 虽然绝大多数会在前台处理,但是也有需要从文件流读入的情况,如果日期不合格就需要抛异常,这时候就需要禁止SimpleDateFormat的自动计算功能. 这时 ...

  6. java桌面项目打包_by icewee_写得太棒了,直接转载了

    前言: 我们都知道Java可以将二进制程序打包成可执行jar文件,双击这个jar和双击exe效果是一样一样的,但感觉还是不同.其实将java程序打包成exe也需要这个可执行jar文件. 准备: ecl ...

  7. Delphi 编写的Web Service

      一编写服务程序 第一步:File----->New----->Other------>WebServices----->Soap Server Application选择I ...

  8. URAL1079

    Problem E Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 32768/16384K (Java/Other) Total Sub ...

  9. HDOJ/HDU 1133 Buy the Ticket(数论~卡特兰数~大数~)

    Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the next ...

  10. asp 数组

    定义简单数组 有两种方法在asp中定义和初始化数组,让我们看看每种的例子: 方法一:MyArray = Array("Jan","Feb","Mar& ...