Oracle学习笔记_10_判断是否为日期类型

简介:     FUNCTION isdate (datestr VARCHAR2, format VARCHAR2) RETURN number IS p_date DATE; BEGIN SELECT TO_DATE (datestr, format) ...

 

 

 

FUNCTION isdate (datestr VARCHAR2, format VARCHAR2) RETURN number IS
    p_date   DATE;
BEGIN
    SELECT TO_DATE (datestr, format)
    INTO p_date
    FROM DUAL;
    RETURN 1;
EXCEPTION
    WHEN OTHERS  THEN
       RETURN 0;
END;

 

 

 

 

多条件模糊查询时:

function get_date_str ( p_date varchar2) return varchar2 is
     v_date   date;
  begin

     if ( length(p_date) = 4 ) then
         select to_date (p_date, 'yyyy')
         into v_date
         from dual;
         return to_char( v_date ,'yy');
           
     elsif ( length(p_date) = 6 )then
         select to_date (p_date, 'yyyymm')
         into v_date
         from dual;
         return to_char( v_date ,'mm')  || '月-' ||  to_char( v_date,'yy');
         
     elsif ( length(p_date) = 7 )then
         select to_date (p_date, 'yyyy-mm')
         into v_date
         from dual;
         return to_char( v_date ,'mm')  || '月-' ||  to_char( v_date,'yy');             
         
     elsif ( length(p_date) = 8 ) then
         select to_date (p_date, 'yyyymmdd')
         into v_date
         from dual;
         return  to_char(v_date,'dd') || '-' || to_char( v_date,'mm')  || '月-' ||  to_char(v_date,'yy');

     elsif ( length(p_date) = 10 ) then
         select to_date (p_date, 'yyyy-mm-dd')
         into v_date
         from dual;
         return  to_char(v_date,'dd') || '-' || to_char( v_date,'mm')  || '月-' ||  to_char(v_date,'yy');
        
     end if;
     
     return '11-00月-00';
     
  exception
    when others then
       return '00-00月-00';
  end get_date_str;
View Code

 

 

附录:参考资料

1.oracle中判断是否为日期/number格式

 

目录
相关文章
|
4月前
|
SQL Oracle 关系型数据库
Oracle之日期计算相关函数
Oracle之日期计算相关函数
45 0
|
4月前
|
SQL Oracle 关系型数据库
java往oracle存clob类型的值时,字符长度过长怎么办?
java往oracle存clob类型的值时,字符长度过长怎么办?
70 1
|
2月前
|
Oracle 关系型数据库 数据库
Flink Sink to Oracle 存在字段CLOB类型,如何处理错误”ORA-01461: 仅能绑定要插入LONG的LONG值“
做Flink CDC同步数据过程中,目标是Oracle数据库,其中某个字段较大被设置为CLOB类型,其中会遇到异常,”ORA-01461: 仅能绑定要插入LONG的LONG值“
|
2月前
|
Oracle 关系型数据库 数据处理
某教程学习笔记(一):10、oracle数据库注入
某教程学习笔记(一):10、oracle数据库注入
17 0
|
3月前
|
SQL Oracle 关系型数据库
Oracle PL/SQL 第五章–复合类型
Oracle PL/SQL 第五章–复合类型
|
4月前
|
SQL Oracle 关系型数据库
oracle中日期循环
oracle中日期循环
60 0
|
9月前
|
SQL 存储 Oracle
Oracle数据库中日期的操作、主键自增与分页查询
Oracle数据库中日期的操作、主键自增与分页查询
80 0
|
5月前
|
Oracle 关系型数据库 数据库
在Flink CDC中,使用Oracle 11g数据库的NUMBER类型作为主键
在Flink CDC中,使用Oracle 11g数据库的NUMBER类型作为主键
48 1
|
8月前
|
Oracle 关系型数据库 数据库
Oracle 数据库中常见的日期和时间函数
Oracle 数据库中常见的日期和时间函数
142 0
|
8月前
|
Oracle 关系型数据库
Oracle日期加减运算实战演练
Oracle日期加减运算实战演练
60 0

推荐镜像

更多