巷尾的酒吧

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  64 Posts :: 0 Stories :: 5 Comments :: 0 Trackbacks

#

     摘要: l        方括号表达示方括号表达式描述[[:alnum:]]字母和数字混合的字符[[:alpha:]]字母字符[[:cntrl:]]控制字符[[:digit:]]数字字符[[:graph:]]图像字符[[:lower:]]小写字母字符[[:print:]]打印字符[[:punct:]]标点符号字符[[:spac...  阅读全文
posted @ 2012-10-11 20:06 abing 阅读(282) | 评论 (0)编辑 收藏

简要比较:

      replace 字符串级别的代替

     如:SELECT REPLACE('accd','cd','ef') from dual; --> aefd

 

     translate 字符级别的代替

     如:select translate('acdd','cd','ef') from dual; -->aeff


replace('将要更改的字符串','被替换掉的字符串','替换字符串')

例:select  replace ('111222333444','222','888') from dual;

输出为 '111888333444'


分别详解

     replace:

     语法:REPLACE(char,search_string[,replacement_string])

     解释:replace中,每个search_string都被replacement_string所代替

        select replace('acdd','cd','ef') from dual; --> aefd

 

     如果replacement_string为空或为null,那么所有的search_string都被移除

     select replace('acdd','cd','') from dual; --> ad

 

     如果search_string 为null,那么就返回原来的char

     select replace('acdd','ef') from dual; -->acdd

     select replace('acdd','','') from dual; -->acdd(也是两者都为空的情况)

 

 

      translate:

      语法:TRANSLATE('char','from_string','to_string')

      解释:translate中,每个from_string中的字符被to_string中

        

        举例说明:


        select translate('asd12fg','12','55') from dual

posted @ 2012-10-11 19:55 abing 阅读(197) | 评论 (0)编辑 收藏

oracle的substr函数的用法
 取得字符串中指定起始位置和长度的字符串   substr( string, start_position, [ length ] )
 如:
     substr('This is a test'62)     would return 'is'
     substr('This is a test'6)     would return 'is a test'
     substr('TechOnTheNet'-33)     would return 'Net'
     substr('TechOnTheNet'-63)     would return 'The'

  select substr('Thisisatest', -4, 2) value from dual    结果是   te

select substr('emros',-3,1) value from dual      结果是 r

 

substr('abcde',-6) = null
substr('abcde',-5) = 'abcde'
substr('abcde',-4) = 'bcde'
substr('abcde',-3) = 'cde'
substr('abcde',-2) = 'de'
substr('abcde',-1) = 'e'
substr('abcde',-0) = 'abcde'

posted @ 2012-10-11 17:49 abing 阅读(205) | 评论 (0)编辑 收藏

INSTR

  (源字符串, 目标字符串, 起始位置, 匹配序号)

  在Oracle/PLSQL中,instr函数返回要截取的字符串在源字符串中的位置。只检索一次,就是说从字符的开始

  到字符的结尾就结束。

  语法如下:

  instr( string1, string2 [, start_position [, nth_appearance ] ] )

  参数分析:

  string1

  源字符串,要在此字符串中查找。

  string2

  要在string1中查找的字符串.

  start_position

  代表string1 的哪个位置开始查找。此参数可选,如果省略默认为1. 字符串索引从1开始。如果此参数为正,从左到右开始检索,如果此参数为负,从右到左检索,返回要查找的字符串在源字符串中的开始索引。

  nth_appearance

  代表要查找第几次出现的string2. 此参数可选,如果省略,默认为 1.如果为负数系统会报错。

  注意:

  如果String2在String1中没有找到,instr函数返回0.



示例如下:

select instr('adsda','a') from dual
select instr('adsda','a',1,2) from dual
select instr('adsda','a',-1,2) from dual






posted @ 2012-10-11 17:46 abing 阅读(175) | 评论 (0)编辑 收藏

ORACLE中的支持正则表达式的函数主要有下面四个:
1,REGEXP_LIKE :与LIKE的功能相似
2,REGEXP_INSTR :与INSTR的功能相似
3,REGEXP_SUBSTR :与SUBSTR的功能相似
4,REGEXP_REPLACE :与REPLACE的功能相似
它们在用法上与Oracle SQL 函数LIKE、INSTR、SUBSTR 和REPLACE 用法相同,
但是它们使用POSIX 正则表达式代替了老的百分号(%)和通配符(_)字符。
POSIX 正则表达式由标准的元字符(metacharacters)所构成:
'^' 匹配输入字符串的开始位置,在方括号表达式中使用,此时它表示不接受该字符集合。
'$' 匹配输入字符串的结尾位置。如果设置了 RegExp 对象的 Multiline 属性,则 $ 也匹
配 '\n' 或 '\r'。
'.' 匹配除换行符之外的任何单字符。
'?' 匹配前面的子表达式零次或一次。
'+' 匹配前面的子表达式一次或多次。
'*' 匹配前面的子表达式零次或多次。
'|' 指明两项之间的一个选择。例子'^([a-z]+|[0-9]+)$'表示所有小写字母或数字组合成的
字符串。
'( )' 标记一个子表达式的开始和结束位置。
'[]' 标记一个中括号表达式。
'{m,n}' 一个精确地出现次数范围,m=<出现次数<=n,'{m}'表示出现m次,'{m,}'表示至少
出现m次。
\num 匹配 num,其中 num 是一个正整数。对所获取的匹配的引用。
字符簇:
[[:alpha:]] 任何字母。
[[:digit:]] 任何数字。
[[:alnum:]] 任何字母和数字。
[[:space:]] 任何白字符。
[[:upper:]] 任何大写字母。
[[:lower:]] 任何小写字母。
[[:punct:]] 任何标点符号。
[[:xdigit:]] 任何16进制的数字,相当于[0-9a-fA-F]。
各种操作符的运算优先级
\转义符
(), (?:), (?=), [] 圆括号和方括号
*, +, ?, {n}, {n,}, {n,m} 限定符
^, $, anymetacharacter 位置和顺序
|
*/
--创建表
create table fzq
(
id varchar(4),
value varchar(10)
);
--数据插入
insert into fzq values
('1','1234560');
insert into fzq values
('2','1234560');
insert into fzq values
('3','1b3b560');
insert into fzq values
('4','abc');
insert into fzq values
('5','abcde');
insert into fzq values
('6','ADREasx');
insert into fzq values
('7','123 45');
insert into fzq values
('8','adc de');
insert into fzq values
('9','adc,.de');
insert into fzq values
('10','1B');
insert into fzq values
('10','abcbvbnb');
insert into fzq values
('11','11114560');
insert into fzq values
('11','11124560');
--regexp_like
--查询value中以1开头60结束的记录并且长度是7位
select * from fzq where value like '1____60';
select * from fzq where regexp_like(value,'1....60');
--查询value中以1开头60结束的记录并且长度是7位并且全部是数字的记录。
--使用like就不是很好实现了。
select * from fzq where regexp_like(value,'1[0-9]{4}60');
-- 也可以这样实现,使用字符集。
select * from fzq where regexp_like(value,'1[[:digit:]]{4}60');
-- 查询value中不是纯数字的记录
select * from fzq where not regexp_like(value,'^[[:digit:]]+$');
-- 查询value中不包含任何数字的记录。
select * from fzq where regexp_like(value,'^[^[:digit:]]+$');
--查询以12或者1b开头的记录.不区分大小写。
select * from fzq where regexp_like(value,'^1[2b]','i');
--查询以12或者1b开头的记录.区分大小写。
select * from fzq where regexp_like(value,'^1[2B]');
-- 查询数据中包含空白的记录。
select * from fzq where regexp_like(value,'[[:space:]]');
--查询所有包含小写字母或者数字的记录。
select * from fzq where regexp_like(value,'^([a-z]+|[0-9]+)$');
--查询任何包含标点符号的记录。
select * from fzq where regexp_like(value,'[[:punct:]]');

例子:判断姓名是否为空,少于两个字符,包含数字和字母

create or replace
FUNCTION CheckName(NameStr in VARCHAR2) RETURN integer
As
BEGIN
--符合返回1,不符合返回0
   if(NameStr is null or length(NameStr)<2) then
      return 0;
   else
      if(NameStr like '%未取名%') then
       RETURN 0;
       end if;
       if regexp_like(NameStr,'^([a-z]+|[0-9]+|[A-Z]+)$') then
       return 0;
       end if;
       return 1;     
   end if;
END CheckName;

posted @ 2012-10-11 17:37 abing 阅读(264) | 评论 (0)编辑 收藏

需求:

匹配手机号,第一位可以是+,可以没有+,后面的全部要是数字,如:

+861359415665

8613659558555

1356856455

都是合法的。

+aa156945555

aa1359556666

aaddssdfdfsd

都是不合法的。

正则:

[sql]
  1. SQL> SELECT * FROM DUAL WHERE regexp_like('+333333' ,'^[\+]*[[:digit:]]+');      --该+转义或者不转义,结果是一样的   
  2.   
  3. DUMMY  
  4. -----   
  5. X  

[sql]

  1. SQL> SELECT * FROM DUAL WHERE regexp_like('aa333333' ,'^[+]*[[:digit:]]+');  
  2.   
  3. DUMMY  
  4. -----  

解释:

1.^代表开始,*表示出现0次或多次,+表示出现1次或多次,[:digit:]代表0-9的纯数字(还有$代表以什么结尾,如果是[[:digit:]]+$代表以数字结尾)。该正则的意思就是:

以+0次或多次开头,紧接着后面数字出现一次或多次(即一定要有数字)。

2.dual表中,永远只有1行记录。查询出dual中有记录,证明where条件成立,反之不成立。

先前写了一个错误的正则:

[sql]
  1. [\+]*[[:digit:]]+  

注意,就只少了一个代表开始符号的^。少了这个符号,说明这个正则的意思是:

+出现0次或多次(即+可以出现,可以不出现!!),紧后面的数字出现1次或多次。前面已经+可以出现0次了,证明没有+也可以,那么就是只要字符串中有数字(+aa111a,aass11111……),这个正则恒成立,错误深重啊!!

Oracle正则表达式的应用by 温州--名次

在oracle里正则表达式有四个函数可用,分别是regexp_like、regexp_substr、regexp_instr 和regexp_replace。这里在我们oracle 10g里灵活应用。

       先来简单介绍一下正则表达式的内容,正则表达式是做为快速查询的文本内容的,在linux应用比较多,首先,行的起始与结束 “^”这个字符是表示只查找行首的内容。“$”这个字符只查找行末的内容。接下来是“^”还可以做为一个排除字符来使用。还是使用例子来做一个演示比较明了一下。

       这里我使用regexp_like这个函数来做,这样可以我们平时会使用的比较多。

select * from test_table

where regexp_like(field_1,'^1234')

这个就是表示是以1234打头的字符串是不是有匹配的。这里和like的方式是一样的。

 

 

select * from test_table

where regexp_like(field_1,'^[12]234')

这里多了一个[]这里做一个独立字符,这里表示是以1或2开始,并且接着是234这个里的字符就会是匹配的。

 

 

select * from test_table

where regexp_like(field_1,'^(欧阳|李)小二')

这里我们就可以表达,这个查询一个姓是欧阳或李的,名字叫小二的字符串。这里多了一个()这个是做一个为字符串的方式来写的与[]刚好是对应。

这里还有一个“|”来表示或的意思。

 

 

select * from test_table

where regexp_like(field_1,'^李[小]*二')

这里我们就可以查询李小二或是李二,再或者是李小小二,都可以,这里我们需要讲一下是[]后面带了一个*,这个是表示0~无穷大 字符去匹配。这个[]我们还可以添加一个“+”来表示1~无穷大的字符去匹配,也可以更加精准一些,在[]后面{1,3}这里就是表示1个到3个相同字符的匹配。还有一个“?”来说表示1或是0个。

 

 

select * from test_table

where regexp_like(field_1,'李[^小]二')

这里我们可以查询到姓李的,但是第二字不是“小”这个字。

 

 

select * from test_table

where regexp_like(field_1,'[0-9]')

这里是表示我们查询字符串含有0-9的数字的字符串。

 

 

select * from test_table

where regexp_like(field_1,'[a-z]')

这里是表示我们查询字符串含有a-z的小写字母的字符串。

 

 

select * from test_table

where regexp_like(field_1,'[A-z]')

这里是表示我们查询字符串含有A-z的所有字母的字符串。

 

 

select * from test_table

where regexp_like(name,'[[:alpha:]]')

这里是表示查询匹配任意字母,也包括中文字

 

 

select * from test_table

where regexp_like(name,'[[:alnum:]]')

这里是表示查询匹配任意字母和数字

 

 

select * from test_table

where regexp_like(name,'[[:digit:]]')

这里是表示查询匹配任意数字

 

 

Select * from test_table

Where regexp_like(name,’of’,’i’)

这里就是of不区分大小写

 

 

Select * from test_table

Where regexp_like(name,’^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$’)

这样我们可以查询是不是ip格式

 

 

 

接下来介绍一下regexp_substr

这个也是一个非常实用的一个函数

 

 REGEXP_SUBSTR与SUBSTR函数相同,返回截取的子字符串

REGEXP_SUBSTR(srcstr, pattern [, position [, occurrence [, match_option]]])

注:

srcstr 源字符串

pattern 正则表达式样式

position 开始匹配字符位置

occurrence 匹配出现次数

match_option 匹配选项(区分大小写)

 

 

SELECT regexp_substr('1PSN/231_3253/ABc', '[[:alnum:]]+') FROM dual;

Output: 1PSN

[[:alnum:]]+ 表示匹配1个或者多个字母或数字字符

 

 

SELECT regexp_substr('1PSN/231_3253/ABc', '[[:alnum:]]+', 1, 2) FROM dual;

Output: 231

与上面一个例子相比,多了两个参数

1 表示从源字符串的第一个字符开始查找匹配

2 表示第2次匹配到的字符串(默认值是“1”,如上例)

 

 

select regexp_substr('@@/231_3253/ABc','@*[[:alnum:]]+') from dual;

Output: 231

@* 表示匹配0个或者多个@

[[:alnum:]]+ 表示匹配1个或者多个字母或数字字符

注意:需要区别“+”和“*”的区别

 

 

select regexp_substr('1@/231_3253/ABc','@+[[:alnum:]]*') from dual;

Output: @

@+ 表示匹配1个或者多个@

[[:alnum:]]* 表示匹配0个或者多个字母或数字字符

 

 

select regexp_substr('1@/231_3253/ABc','@+[[:alnum:]]+') from dual;

Output: Null

@+ 表示匹配1个或者多个@

[[:alnum:]]+ 表示匹配1个或者多个字母或数字字符

 

 

select regexp_substr('@1PSN/231_3253/ABc125','[[:digit:]]+$') from dual;

Output: 125

[[:digit:]]+$ 表示匹配1个或者多个数字结尾的字符

 

 

select regexp_substr('1@/231_3253/ABc','@+[[:alnum:]]+') from dual;

Output: Null

@+ 表示匹配1个或者多个@

[[:alnum:]]+ 表示匹配1个或者多个字母或数字字符

 

 

select regexp_substr('@1PSN/231_3253/ABc125','[[:digit:]]+$') from dual;

Output: 125

[[:digit:]]+$ 表示匹配1个或者多个数字结尾的字符

 

 

select regexp_substr('@1PSN/231_3253/ABc','[^[:digit:]]+$') from dual;

Output: /ABc

[^[:digit:]]+$ 表示匹配1个或者多个不是数字结尾的字符

 

 

select regexp_substr('Tom_Kyte@oracle.com','[^@]+') from dual;

Output: Tom_Kyte

[^@]+ 表示匹配1个或者多个不是“@”的字符

 

 

select regexp_substr('1PSN/231_3253/ABc','[[:alnum:]]*',1,2)

from dual;

Output: Null

[[:alnum:]]* 表示匹配0个或者多个字母或者数字字符

注:因为是匹配0个或者多个,所以这里第2次匹配的是“/”(匹配了0次),而不是“231”,所以结果是“Null”

 

 

这里我们有时候会查询字符串里asdfafd<main>dafda 这里我们要取出<main>这个字符串

Select regexp_substr('asdfafd<main>dafda','<[^>]+>') from dual

Output: <main>

这里我们在<>中间去一个^>这样在匹配<之后,在向后查询的时候确保在匹配到>之前不再在有>,不然的话就要有可以出错的情况。

 

 

Select regexp_substr('asdfafd<main>da>fda','<[^<]+>') from dual

Output: <main>da>

在这个例子中,我们在<main>之后还在da>,这样的话,如果我们没有添加^>,正则表达式就会向后继续去匹配,直到最后一个>为至,这样就会出现偏差

 

 

这个通常用来实现字符串的列传行

select regexp_substr('123;234;345;456;567;678;789','[^;]+',1,rownum) from dual

connect by rownum <= length('123;234;345;456;567;678;789') - length(replace('123;234;345;456;567;678;789',';'))+1

这里length这里操作是先得到有多少个“;”,再通过 connect by rownum方式来做一行成多行的操作,在变成多行之后,可以通过regexp_substr来取字符串的操作

 

 

接着上一个例子

a,b,c,d,e,d,f,a,n这样的一个字符串,我们现在要把字符串里一些重复去掉,这样的话结果是a,b,c,d,e,f,n去掉了d与a的两个字符串

select wm_concat(new_row) from (

select distinct regexp_substr('a,b,c,d,e,d,f,a,n','[^,]+',1,rownum) new_row from dual

connect by rownum<=length('a,b,c,d,e,d,f,a,n')-length(replace('a,b,c,d,e,d,f,a,n',',')))

通过转成多行的,再用distinct 去掉重复,然后我们再通过wm_concat来字符串合并来完成。

 

 

再来一个ip格式转换的例子吧,我们一般的IP的格式是12.19.168.27现在要不足3位的补足前面为0,结果是012.019.168.027

select wm_concat(new_value) from (

select

lpad(regexp_substr('12.19.168.27','[^.]+',1,rownum) ,3,'0') new_value,rownum

from dual

connect by rownum<5

order by rownum)

 

 

来一个验证IP是数字是否正确

select count(*) from(

select

lpad(regexp_substr('12.19.168.27','[^.]+',1,rownum) ,3,'0') new_value,rownum

from dual

connect by rownum<5)

where new_value>=0 and new_value<256

having count(*) =4

 

 

来一个IP字符串格式转换成数字型IP

select sum(new_value*power(256,4-rm)) from (

select regexp_substr('12.19.168.27','[^.]+',1,rownum) new_value,rownum rm from dual

connect by rownum<=4

)

 

 

接下来介绍一个regexp_instr函数

 

REGEXP_INSTR 函数使用正则表达式返回搜索模式的起点和终点。REGEXP_INSTR 的语法如下所示。REGEXP_INSTR 返回一个整数,指出搜索模式的开始或结束的位置,如果没有发现匹配的值,则返回0。

 

语法:

2.REGEXP_INSTR与INSTR函数相同,返回字符串位置

REGEXP_INSTR(srcstr, pattern [, position [, occurrence [, return_option [,match_option]]]])

与REGEXP_SUBSTR一样,它也有变量pattern、position(开始位置)、occurrence 和match_parameter;这里主要介绍一下新参数return_option 的作用,它允许用户告诉Oracle,模式出现的时候,要返回什么内容。

 

Select regexp_instr('asdfafd<main>da>fda','sd') from dual

Output:2

这里去查询sd的位置,这个和instr是在相同的

 

 

Select regexp_instr('asdfafd<main>da>fda','da',1,2) from dual

这里是查询da第二出现的位置

 

还有我们经常会遇到一种情况是,查询某个字段,如果是等于“上海”或“北京”或者我们温州就写成大城市,其它的写成小城市,我们一般会考虑使用decode这种方式

 

Select decode('上海','上海','大城市','北京' ,'大城市' ,'温州' ,'大城市','小城市') from dual

只有两个我们可能觉的sql也不是很冗长,如果有四五个的话,就有点长了,这里使用regexp_instr就可以很多的去操作

 

Select decode (regexp_instr('北京','^(上海|北京|温州)'),0,'小城市', '大城市') from dual

通过regexp_instr不匹配时为0的条件,这样就可以完成了

 

 

 

最后一个函数regexp_replace

REGEXP_REPLACE 函数是用另外一个值来替代串中的某个值。例如,可以用一个匹配数字来替代字母的每一次出现。REGEXP_REPLACE的格式如下所示

 

语法:

4.REGEXP_REPLACE与REPLACE函数相同,替换原字符串中的字符内容

REGEXP_REPLACE(srcstr, pattern [,replacestr [, position [, occurrence [,match_option]]]])

 

 

这个替换函数还是一个非常好用的。

如我们在有一个字符串adfadfa (main) next 现在我们要把()替换成<>,这里我们可能想用replace就可以搞定了,但是我们现在做的是(之后必须有)这样的()我们才替换把<>.

select regexp_replace('adfadfa (main) next ','(\()([^\)]*)(\))','<\2>') from dual

output: adfadfa <main> next

这里还是一个\做为转义字符。

 

再来一个ip格式转换的例子吧,我们一般的IP的格式是12.19.168.27现在要不足3位的补足前面为0,结果是012.019.168.027

select regexp_replace(

regexp_replace('12.19.168.27','([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3})',

'00\1.00\2.00\3.00\4') ,

'([0-9]*)([0-9]{3}\.)([0-9]*)([0-9]{3}\.)([0-9]*)([0-9]{3}\.)([0-9]*)([0-9]{3}$)','\2\4\6\8')

from dual

output: 012.019.168.027

这里我分成两步来操作,regexp_replace('12.19.168.27','([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3})',

'00\1.00\2.00\3.00\4')我首先让每个小字符串做添加0,这样每个字符串都会大于3,再

'([0-9]*)([0-9]{3}\.)([0-9]*)([0-9]{3}\.)([0-9]*)([0-9]{3}\.)([0-9]*)([0-9]{3}$)','\2\4\6\8')

这整个字符串分成8段,这样我们只要2、4、6、8这四个段就可以了。

 

 

下面一个例子中,在每两个字符之间插入一个空格符

SELECT regexp_replace('YAHOO', '(.)', '\1 ') AS output FROM dual;

Output: Y A H O O

这个用一个循环的方式去操作,还蛮好的。

 

 

select regexp_replace(

regexp_replace('12.19.168.27','([^.]+)'

,'00\1')

,'([^.]*)([^.]{3})','\2')

from dual

接着刚才那个,我们可以把replace循环替换的方式来操作。

posted @ 2012-10-11 17:09 abing 阅读(364) | 评论 (0)编辑 收藏

正则表达式,给我写个1,2,3,4 或者4,1,2,3   匹配出4 来 
select regexp_substr('1,2,3,4','[4]') tony from dual;
select regexp_substr('4,3,2,1','[4]') tony from dual;
oracle  验证电话号码(手机号码):

/**
 * 手机号码
 * 移动:134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
 * 联通:130,131,132,152,155,156,185,186
 * 电信:133,1349,153,180,189
 */
select t.* from myregex t where regexp_like(t.name,'^1(3[0-9]|5[0-35-9]|8[025-9])[0-9]{8}$')
select t.* from myregex t where regexp_like(t.name,'^1(3[0-9]|5[0-35-9]|8[025-9])?[0-9]{8}?$')
select t.* from myregex t where regexp_like(t.name,'^1(3[[:digit:]]|5[0-35-9]|8[025-9])?[[:digit:]]{8}?$')
/**
 * 中国移动:China Mobile
 * 134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
 */
select t.* from myregex t where regexp_like(t.name,'^1(34[0-8]?|3[5-9]?|5[017-9]?|8[278]?)[0-9]{8}$')
select t.* from myregex t where regexp_like(t.name,'^1(34[0-8]?|3[5-9]?|5[017-9]?|8[278]?)[[:digit:]]{8}$')
/**
 * 中国联通:China Unicom
 * 130,131,132,152,155,156,185,186
 */
select t.* from myregex t where regexp_like(t.name,'^1(3[0-2]?|5[25-6]?|8[5-6]?)[0-9]{8}$')
select t.* from myregex t where regexp_like(t.name,'^1(3[0-2]?|5[25-6]?|8[5-6]?)[[:digit:]]{8}$')
/**
 * 中国电信:China Telecom
 * 133,1349,153,180,189
 */
select t.* from myregex t where regexp_like(t.name,'^1((33?|53?|8[09]?)[0-9]?|349)[0-9]{7}$')
select t.* from myregex t where regexp_like(t.name,'^1((33?|53?|8[09]?)[0-9]?|349)[[:digit:]]{7}$')


posted @ 2012-10-11 17:03 abing 阅读(203) | 评论 (0)编辑 收藏

NULL指的是空值,或者非法值。
NVL (expr1, expr2)->expr1为NULL,返回expr2;不为NULL,返回expr1。注意两者的类型要一致
NVL2 (expr1, expr2, expr3) ->expr1不为NULL,返回expr2;为NULL,返回expr3。expr2和expr3类型不同的话,expr3会转换为expr2的类型
select t.empno,nvl2(t.mgr,'the value is not null','the value is null') from emp t where t.deptno in (select s.deptno from dept s where s.deptno='1')
NULLIF (expr1, expr2) ->相等返回NULL,不等返回expr1
select t.empno,nullif(t.mgr,'tom') from emp t where t.deptno in (select s.deptno from dept s where s.deptno='1')
posted @ 2012-10-11 13:58 abing 阅读(173) | 评论 (0)编辑 收藏

select t.empno,nvl(t.mgr,'MGR') from emp t where t.deptno in (select s.deptno from dept s where s.deptno='1')
select t.empno,nvl(t.mgr,'MGR') from emp t where exists (select s.deptno from emp s where s.deptno='1' and t.deptno=s.deptno)
select t.empno,nvl(t.mgr,'MGR') from emp t where t.deptno is not null and exists (select s.deptno from emp s where s.deptno='1' and t.deptno=s.deptno)
select t.empno,nvl(t.mgr,'MGR') from emp t where not exists (select s.* from dept s where s.deptno  in(2,3) and t.deptno=s.deptno)
select t.empno,nvl(t.mgr,'MGR') from emp t where t.deptno in (select s.deptno from dept s where s.deptno not in(2,3))































posted @ 2012-10-11 13:31 abing 阅读(174) | 评论 (0)编辑 收藏

package com.abin.lee.servlet.regex;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexTest {
public static boolean isRight(String validate){
String regex="/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/";//邮箱正则1
// String regex="(^[\\w]*@[a-zA-Z]+[.][a-zA-Z]+$)";//邮箱正则1
// String regex="(^13[0-9]{9}$)|(^15[0-9]{9}$)|(^18[0-9]{9}$)";//电话号码正则
Pattern pattern=Pattern.compile(regex);
Matcher matcher=pattern.matcher(validate);
boolean flag=matcher.matches();
return flag;
}
public static void main(String[] args) {
String validate="varyall@tom.com";
boolean flag=isRight(validate);
System.out.println("flag="+flag);
}
}
posted @ 2012-10-10 00:22 abing 阅读(193) | 评论 (0)编辑 收藏

仅列出标题
共7页: 上一页 1 2 3 4 5 6 7 下一页