|
--加个日期格式验证
SQL> with function fn_valid_date(p_str in varchar2)
2 return int
3 is
4 l_date date;
5 begin
6 l_date := to_date(p_str,'ddmmyy');
7 return 1;
8 exception when others then
9 return 0;
10 end;
11 t as (select level -1 n from dual connect by level <=100),
12 d as (select lpad(n,2,'0') dd from t where n between 1 and 31 and substr(n,1,1)<> nvl(substr(n,2,1),'x')),
13 m as (select lpad(n,2,'0') mm from t where n between 1 and 12 and substr(n,1,1)<> nvl(substr(n,2,1),'x')),
14 y as (select lpad(n,2,'0') yy from t where n between 0 and 99 and substr(n,1,1)<> nvl(substr(n,2,1),'x')),
15 h as (select lpad(n,2,'0') hh from t where n between 0 and 23 and substr(n,1,1)<> nvl(substr(n,2,1),'x')),
16 i as (select lpad(n,2,'0') mi from t where n between 0 and 59 and substr(n,1,1)<> nvl(substr(n,2,1),'x')),
17 s (time_num) as (
18 select dd||mm||yy||hh||mi time_num
19 from d,m,y,h,i
20 where instr(dd,substr(mm,1,1))=0 and instr(dd,substr(mm,2,1))=0
21 and instr(dd||mm,substr(yy,1,1))=0 and instr(dd||mm,substr(yy,2,1))=0
22 and instr(dd||mm||yy,substr(hh,1,1))=0 and instr(dd||mm||yy,substr(hh,2,1))=0
23 and instr(dd||mm||yy||hh,substr(mi,1,1))=0 and instr(dd||mm||yy||hh,substr(mi,2,1))=0
24 and fn_valid_date (dd||mm||yy) = 1
25 )
26 select min(abs(a.time_num - b.time_num)),max(abs(a.time_num - b.time_num))
27 from s a,s b
28 where a.time_num <> b.time_num
29 /
MIN(ABS(A.TIME_NUM-B.TIME_NUM) MAX(ABS(A.TIME_NUM-B.TIME_NUM)
------------------------------ ------------------------------
9 1501979184 |
|