免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1325 | 回复: 7
打印 上一主题 下一主题

sql问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-09-26 11:11 |只看该作者 |倒序浏览
在oracle8.05中
如何利用sql语句 判断日期是否合法
我的情况如下:
表中的出生年月日格式 yyyy-mm-dd  varchar(10) 其中有不合法 例如1956-02-31,1978-13-01//因为varchar类型
还有其他错误情况
一句sql能否取日期出错误记录

论坛徽章:
0
2 [报告]
发表于 2003-09-26 11:40 |只看该作者

sql问题

try this

select birth_date from your_table
where substr(birth_date, 6,2)='02' and
  (substr(birth_date, 9,2)='00' or substr(birth_date, 9,2) >;= 29);

论坛徽章:
0
3 [报告]
发表于 2003-09-26 12:03 |只看该作者

sql问题

原帖由 "szhang" 发表:
try this

select birth_date from your_table
where substr(birth_date, 6,2)='02' and
  (substr(birth_date, 9,2)='00' or substr(birth_date, 9,2) >;= 29);
   
情况不全 这样的呢 1956-78-23

论坛徽章:
0
4 [报告]
发表于 2003-09-26 12:40 |只看该作者

sql问题

晕,那就继续追加条件啊!!!

论坛徽章:
0
5 [报告]
发表于 2003-09-26 13:16 |只看该作者

sql问题

先建立一个函数用于判断日期
create or replace function isdate(v in varchar2) return number
is
d date;
begin
d := to_date(v,'yyyy-mm-dd');
return 1;
exception
when others then
   return 0;
end;
/

然后用:1是 0否
select isdate(d) from test;

论坛徽章:
0
6 [报告]
发表于 2003-09-26 20:53 |只看该作者

sql问题

[quote]原帖由 "rollingpig"]晕,那就继续追加条件啊!!![/quote 发表:
     
晕 那么多种情况你都加上阿

论坛徽章:
0
7 [报告]
发表于 2003-09-27 08:49 |只看该作者

sql问题

呵呵,还是用zhouok      的方法吧

论坛徽章:
0
8 [报告]
发表于 2003-09-27 12:59 |只看该作者

sql问题

try this
select birth_date from your_table
where substr(birth_date, 6,2) in ('01','03','05','07','08','10','12')
        and (substr(birth_date, 9,2)='00' or substr(birth_date, 9,2) >; '31');
  or substr(birth_date, 6,2) in ('04','06, '09','11')
        and (substr(birth_date, 9,2)='00' or substr(birth_date, 9,2) >; '30')
  or substr(birth_date, 6,2)='02'
         and (substr(birth_date, 9,2)='00' or substr(birth_date, 9,2) >; 2
         and substr(birth_date,1,4) in ('1993','1994','1995','1997','1998','1999','2001',2002',2003')
  or substr(birth_date, 6,2)='02'
         and (substr(birth_date, 9,2)='00' or substr(birth_date, 9,2) >; 29)
         and substr(birth_date,1,4) in ('1996','2000','2004');
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP