日期:2014-05-17  浏览次数:20917 次

谁知道PL/SQL中如何判断一个变量是否是"YYYY/MM"形式?
如题!

------解决方案--------------------
SQL> declare
2 v_str varchar2(2000);
3 v_num integer;
4 begin
5 begin
6 v_str := '1234/12 ';
7 select 1 into v_num from dual where REGEXP_LIKE(v_str, '^[0-9]{4}/[0-9]{2}$ ');
8 dbms_output.put_line( 'String ' || v_str || ' fits ' 'yyyy/mm ' ' ');
9 exception when no_data_found then
10 dbms_output.put_line( 'String ' || v_str || ' doesn ' 't fit ' 'yyyy/mm ' ' ');
11 end;
12 begin
13 v_str := '1234\12 ';
14 select 1 into v_num from dual where REGEXP_LIKE(v_str, '^[0-9]{4}/[0-9]{2}$ ');
15 dbms_output.put_line( 'String ' || v_str || ' fits ' 'yyyy/mm ' ' ');
16 exception when no_data_found then
17 dbms_output.put_line( 'String ' || v_str || ' doesn ' 't fit ' 'yyyy/mm ' ' ');
18 end ;
19 begin
20 v_str := '124/12 ';
21 select 1 into v_num from dual where REGEXP_LIKE(v_str, '^[0-9]{4}/[0-9]{2}$ ');
22 dbms_output.put_line( 'String ' || v_str || ' fits ' 'yyyy/mm ' ' ');
23 exception when no_data_found then
24 dbms_output.put_line( 'String ' || v_str || ' doesn ' 't fit ' 'yyyy/mm ' ' ');
25 end ;
26 end;
27 /

String 1234/12 fits 'yyyy/mm '
String 1234\12 doesn 't fit 'yyyy/mm '
String 124/12 doesn 't fit 'yyyy/mm '

PL/SQL procedure successfully completed