﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-巷尾的酒吧-随笔分类-oracle</title><link>http://www.blogjava.net/abin/category/52769.html</link><description /><language>zh-cn</language><lastBuildDate>Fri, 07 Jun 2013 04:27:35 GMT</lastBuildDate><pubDate>Fri, 07 Jun 2013 04:27:35 GMT</pubDate><ttl>60</ttl><item><title>oracle 创建表，序列，索引，视图，触发器，函数，存储过程，定时器，包体</title><link>http://www.blogjava.net/abin/archive/2013/06/02/400082.html</link><dc:creator>abing</dc:creator><author>abing</author><pubDate>Sun, 02 Jun 2013 15:26:00 GMT</pubDate><guid>http://www.blogjava.net/abin/archive/2013/06/02/400082.html</guid><wfw:comment>http://www.blogjava.net/abin/comments/400082.html</wfw:comment><comments>http://www.blogjava.net/abin/archive/2013/06/02/400082.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/abin/comments/commentRss/400082.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/abin/services/trackbacks/400082.html</trackback:ping><description><![CDATA[oracle 创建表table：<br />
<div>create table abin1(</div>
<div>id number(20,0) not null,</div>
<div>name varchar2(100)not null,</div>
<div>pwd nvarchar2(100) not null,</div>
<div>create_time date,</div>
<div>constraint pk_abin1 primary key(id)</div>
<div>)</div><br />oracle创建索引（index）：<br />
<div>create index myname on abin1(name);</div><br />oracle创建序列sequence：<br />
<div>create sequence abin1_seq</div>
<div>minvalue 1</div>
<div>maxvalue 999999999</div>
<div>start with 1</div>
<div>increment by 1</div>
<div>cache 20;</div>创建触发器：<br />
<div>create or replace trigger abin1_tri</div>
<div>before insert on abin1</div>
<div>for each row</div>
<div>begin</div>
<div>select abin1_seq.nextval into :new.id from dual;</div>
<div>end;<br /><br /><br />测试一条记录：</div>
<div>insert into abin1 (name,pwd,create_time) values ('abin','lee',sysdate);&nbsp;</div>呵呵，这里插入了数据，主键自增了，说明成功了。<br /><br /><br />创建存储过程procedure：<br />
<div>create or replace procedure abin1_pro</div>
<div>is</div>
<div>cursor mycur is select t.* from abin1 t;</div>
<div>abin mycur%rowtype;</div>
<div>begin</div>
<div>&nbsp; &nbsp; &nbsp;open mycur;</div>
<div>&nbsp; &nbsp; &nbsp;loop</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; fetch mycur into abin;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; if(abin.name='abin')then</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; update abin1 t set t.name='abining',t.pwd=abin.pwd,t.create_time=sysdate where t.id=abin.id;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; commit;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; end if;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; exit when mycur%NOTFOUND;</div>
<div>&nbsp; &nbsp; &nbsp;end loop;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; if(mycur%ISOPEN)then</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;close mycur;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; end if;</div>
<div>end;</div><br /><br />测试存储过程示例：<br />
<div>declare</div>
<div>begin</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; abin1_pro;</div>
<div>end;</div><br /><br />创建oracle函数function：<br />
<div>create or replace function abin_func</div>
<div>return number</div>
<div>is</div>
<div>total number;</div>
<div>begin</div>
<div>select count(1) into total from abin1 t;</div>
<div>return(total);</div>
<div>end;</div>
<div><br /><br />创建测试函数示例：</div>
<div>declare</div>
<div>total number;</div>
<div>begin</div>
<div>&nbsp; &nbsp; &nbsp; total:=abin_func;</div>
<div>&nbsp; &nbsp; &nbsp; dbms_output.put_line(total);</div>
<div>end;</div><br /><br />oracle创建视图：<br />
<div>create or replace view abin1_view</div>
<div>as</div>
<div>select t.* from abin1 t;</div><br /><br />oracle创建package：<br />create or replace package abin_pac is<br />procedure abinpac;<br />end;<br /><br /><br />oracle创建package body：<br />create or replace package body abin_pac is<br />procedure abinpac is<br />total number;<br />begin<br />&nbsp;select count(1) into total from abin1;<br />&nbsp;dbms_output.put_line(total);<br />end;<br />end;<br /><br />测试代码：<br />begin<br />&nbsp;abin_pac.abinpac;<br />end;<br /><br /><br /><br /><img src ="http://www.blogjava.net/abin/aggbug/400082.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/abin/" target="_blank">abing</a> 2013-06-02 23:26 <a href="http://www.blogjava.net/abin/archive/2013/06/02/400082.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>oracle 常用函数</title><link>http://www.blogjava.net/abin/archive/2012/12/02/392349.html</link><dc:creator>abing</dc:creator><author>abing</author><pubDate>Sun, 02 Dec 2012 14:43:00 GMT</pubDate><guid>http://www.blogjava.net/abin/archive/2012/12/02/392349.html</guid><wfw:comment>http://www.blogjava.net/abin/comments/392349.html</wfw:comment><comments>http://www.blogjava.net/abin/archive/2012/12/02/392349.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/abin/comments/commentRss/392349.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/abin/services/trackbacks/392349.html</trackback:ping><description><![CDATA[<div></div><div>select concat('1','2') zhao from dual;</div><div>select initcap('abin') from dual;</div><div>select lower('ABIN') from dual;</div><div>select upper('abin') from dual;</div><div>select lpad('abin',10,'*') from dual;</div><div>select rpad('abin',7,'*') from dual;</div><div>select ltrim('aaaabain','a') from dual;</div><div>select rtrim('abinaa','a') from dual;</div><div>select trim('a' from 'ababina') from dual;</div><div>select ceil(3.1415926) from dual;</div><div>select floor(3.1415926) from dual;</div><div>select sign(-123) zheng,sign(123) fu ,sign(0) ling from dual;</div><div>select last_day(sysdate-1) from dual;</div><div>select nvl('','0') from dual;</div><div>select nullif('abin','abina') from dual;</div><div>select nvl2('aa','abin','varyall') from dual;</div><div>select coalesce('','1','2') from dual;<br /><br /></div><div><div id="cnblogs_post_body"><p style="text-indent: 21pt">Coalesce<span style="font-family: 宋体">函数</span></p> <p style="text-indent: 21pt">Coalese<span style="font-family: 宋体">函数的作用是的</span>NVL<span style="font-family: 宋体">的函数有点相似，其优势是有更多的选项。</span></p> <p style="text-indent: 21pt"><span style="font-family: 宋体">格式如下：</span></p> <p style="text-indent: 21pt">Coalesce(expr1, expr2, expr3&#8230;.. exprn)</p> <p>Coalesce<span style="font-family: 宋体">是这样来处理这些参数的。如果第一个参数为空，则看第二个参数是否是空，否则则显示第一个参数，如果第二个参数是空再看第三个参数是否为空，否则显示第二个参数，依次类推。</span></p> <p><span style="font-family: 宋体">这个函数实际上是</span>NVL<span style="font-family: 宋体">的循环使用，在此就不举例子了。</span></p></div></div><div></div><div></div><img src ="http://www.blogjava.net/abin/aggbug/392349.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/abin/" target="_blank">abing</a> 2012-12-02 22:43 <a href="http://www.blogjava.net/abin/archive/2012/12/02/392349.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pl/sql中按F8执行单行语句</title><link>http://www.blogjava.net/abin/archive/2012/12/02/392347.html</link><dc:creator>abing</dc:creator><author>abing</author><pubDate>Sun, 02 Dec 2012 12:25:00 GMT</pubDate><guid>http://www.blogjava.net/abin/archive/2012/12/02/392347.html</guid><wfw:comment>http://www.blogjava.net/abin/comments/392347.html</wfw:comment><comments>http://www.blogjava.net/abin/archive/2012/12/02/392347.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/abin/comments/commentRss/392347.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/abin/services/trackbacks/392347.html</trackback:ping><description><![CDATA[<p style="margin: 0px; padding: 0px; color: #454545; font-family: tahoma, helvetica, arial; background-color: #ffffff; "><span style="font-size: 18px; "><span style="font-size: 14px; ">pl/sql中设置:</span></span><strong><span style="font-size: 18px; "><br /></span></strong></p><p style="margin: 0px; padding: 0px; color: #454545; font-family: tahoma, helvetica, arial; background-color: #ffffff; "><strong><span style="font-size: 18px; ">tools-&gt;preferences-&gt;sql&nbsp;window-&gt;AutoSelect&nbsp;statement</span></strong><br /></p><p style="margin: 0px; padding: 0px; color: #454545; font-family: tahoma, helvetica, arial; background-color: #ffffff; ">然后光标放在一行，按F8就可以了,&nbsp;注意:&nbsp;每个语句结尾还要分号标注一下！</p><img src ="http://www.blogjava.net/abin/aggbug/392347.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/abin/" target="_blank">abing</a> 2012-12-02 20:25 <a href="http://www.blogjava.net/abin/archive/2012/12/02/392347.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>oracle  connect by nocycle prior</title><link>http://www.blogjava.net/abin/archive/2012/11/12/391201.html</link><dc:creator>abing</dc:creator><author>abing</author><pubDate>Mon, 12 Nov 2012 06:33:00 GMT</pubDate><guid>http://www.blogjava.net/abin/archive/2012/11/12/391201.html</guid><wfw:comment>http://www.blogjava.net/abin/comments/391201.html</wfw:comment><comments>http://www.blogjava.net/abin/archive/2012/11/12/391201.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/abin/comments/commentRss/391201.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/abin/services/trackbacks/391201.html</trackback:ping><description><![CDATA[创建表：<br />CREATE TABLE T_TREE (ID NUMBER, FATHER_ID NUMBER, NAME VARCHAR2(30));<br /><br />插入数据：<br />
<p>　 INSERT INTO T_TREE VALUES (1, 0, 'A');</p>
<p>　 INSERT INTO T_TREE VALUES (2, 1, 'BC');</p>
<p>　 INSERT INTO T_TREE VALUES (3, 1, 'DE');</p>
<p>　 INSERT INTO T_TREE VALUES (4, 1, 'FG');</p>
<p>　 INSERT INTO T_TREE VALUES (5, 2, 'HIJ');</p>
<p>　 INSERT INTO T_TREE VALUES (6, 4, 'KLM');</p>
<p>　 INSERT INTO T_TREE VALUES (7, 6, 'NOPQ');</p>
<p>　 INSERT INTO T_TREE VALUES (0, 0, 'ROOT');</p>
<p>　 INSERT INTO T_TREE VALUES (4, 7, 'FG');</p>
<p>&nbsp;<br /><br /><br /><br />select * from t_tree t start with t.id=0 connect by nocycle prior t.id=t.father_id<br /><br /><br /><a href="http://www.blogjava.net/freeman1984/archive/2011/05/06/349668.html">http://www.blogjava.net/freeman1984/archive/2011/05/06/349668.html</a></p><img src ="http://www.blogjava.net/abin/aggbug/391201.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/abin/" target="_blank">abing</a> 2012-11-12 14:33 <a href="http://www.blogjava.net/abin/archive/2012/11/12/391201.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Oracle截取字符串和查找字符串  </title><link>http://www.blogjava.net/abin/archive/2012/10/25/390216.html</link><dc:creator>abing</dc:creator><author>abing</author><pubDate>Thu, 25 Oct 2012 05:53:00 GMT</pubDate><guid>http://www.blogjava.net/abin/archive/2012/10/25/390216.html</guid><wfw:comment>http://www.blogjava.net/abin/comments/390216.html</wfw:comment><comments>http://www.blogjava.net/abin/archive/2012/10/25/390216.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/abin/comments/commentRss/390216.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/abin/services/trackbacks/390216.html</trackback:ping><description><![CDATA[<p align="left">oracle 截取字符(substr)，检索字符位置(instr) case when then else end语句使用 收藏  <br />常用函数：substr和instr<br />1.SUBSTR（string,start_position,[length]）&nbsp;&nbsp;&nbsp;  求子字符串，返回字符串<br />解释：string 元字符串<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; start_position&nbsp;&nbsp; 开始位置（从0开始）<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  length 可选项，子字符串的个数<br />For example:<br />substr("ABCDEFG", 0); //返回：ABCDEFG，截取所有字符  <br />substr("ABCDEFG", 2); //返回：CDEFG，截取从C开始之后所有字符 <br />substr("ABCDEFG", 0, 3);  //返回：ABC，截取从A开始3个字符 <br />substr("ABCDEFG", 0, 100);  //返回：ABCDEFG，100虽然超出预处理的字符串最长度，但不会影响返回结果，系统按预处理字符串最大数量返回。 <br />substr("ABCDEFG",  0, -3); //返回：EFG，注意参数-3，为负值时表示从尾部开始算起，字符串排列位置不变。</p> <p>2.INSTR（string,subString,position,ocurrence）查找字符串位置<br />解释：string：源字符串<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  subString：要查找的子字符串<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; position：查找的开始位置<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  ocurrence：源字符串中第几次出现的子字符串<br />For example:<br />INSTR('CORPORATE FLOOR','OR', 3,  2)中，源字符串为'CORPORATE FLOOR', 目标字符串为'OR'，起始位置为3，取第2个匹配项的位置；返回结果为 14 '<br /><br /><br /><br /><br /><div clearfix"=""><h2>oracle中length()与lengthb()区别</h2></div> <div id="content" mod-cs-content="" text-content=""  clearfix"=""> <p><strong>oracle中length()与lengthb()区别</strong></p> <p>&nbsp;</p> <p><strong>OracleSQL.oracle中length()与lengthb()区别 </strong><br />SQL&gt; select  length('阿猪') from dual; <br />LENGTH('阿猪') <br />-------------- <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2  </p> <p>SQL&gt; select lengthb('阿猪') from dual; </p> <p>LENGTHB('阿猪') <br />--------------- <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4 </p> <p><br /><strong>区别：length求得是字符长度，lengthb求得是字节长度。 </strong></p> <p>----------------------------------------------------------------------------------------------------</p>SQL&gt;  select sysdate from dual;<br /><br />SYSDATE<br />--------------<br />26-9月  -05<br /><br />SQL&gt; select length(sysdate) from  dual;<br /><br />LENGTH(SYSDATE)<br />---------------<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;9<br /><br />SQL&gt; select lengthb(sysdate) from  dual;<br /><br />LENGTHB(SYSDATE)<br />----------------<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;10<br /><br />length返回的是字符数<br />lengthb返回的是字节数<br />汉字&#8220;月&#8221;在length时，返回的时1<br />而在lengthb时返回的时2<strong></strong> <p><strong></strong>&nbsp;</p> <p><strong>&nbsp;length指的是字符个数，lengthb指的是字节数。字符个数跟数据库字符集有很大关系。length和lengthb的参数都为varchar2型，因此length(sysdate)有一个隐式的类型转换，实际上等同于length(to_char(sysdate))，ORACLE安装好后默认的NLS_DATE_FORMAT参数值为DD-MON-RR，结果就相当于length('28-9月  -05')和<br />lengthb('28-9月 -05')了，其结果就是9和10</strong></p></div></p><img src ="http://www.blogjava.net/abin/aggbug/390216.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/abin/" target="_blank">abing</a> 2012-10-25 13:53 <a href="http://www.blogjava.net/abin/archive/2012/10/25/390216.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Oracle merge into </title><link>http://www.blogjava.net/abin/archive/2012/10/19/389872.html</link><dc:creator>abing</dc:creator><author>abing</author><pubDate>Fri, 19 Oct 2012 06:58:00 GMT</pubDate><guid>http://www.blogjava.net/abin/archive/2012/10/19/389872.html</guid><wfw:comment>http://www.blogjava.net/abin/comments/389872.html</wfw:comment><comments>http://www.blogjava.net/abin/archive/2012/10/19/389872.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/abin/comments/commentRss/389872.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/abin/services/trackbacks/389872.html</trackback:ping><description><![CDATA[<div>create table ABING1</div><div>(</div><div>&nbsp; ID1 &nbsp; NVARCHAR2(100),</div><div>&nbsp; NAME1 NVARCHAR2(100)</div><div>)<br /><br /><br /><div>create table ABING2</div><div>(</div><div>&nbsp; ID2 &nbsp; NVARCHAR2(100),</div><div>&nbsp; NAME2 NVARCHAR2(100)</div><div>)<br /><br /><br /><div>merge into abing1 t&nbsp;</div><div>using abing2 s</div><div>on(t.id1=s.id2)</div><div>when matched then update set t.name1=s.name2</div><div>when not matched then insert values (s.id2,s.name2);</div><div>commit</div></div></div><img src ="http://www.blogjava.net/abin/aggbug/389872.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/abin/" target="_blank">abing</a> 2012-10-19 14:58 <a href="http://www.blogjava.net/abin/archive/2012/10/19/389872.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>oracle的正则表达式</title><link>http://www.blogjava.net/abin/archive/2012/10/11/389437.html</link><dc:creator>abing</dc:creator><author>abing</author><pubDate>Thu, 11 Oct 2012 12:58:00 GMT</pubDate><guid>http://www.blogjava.net/abin/archive/2012/10/11/389437.html</guid><wfw:comment>http://www.blogjava.net/abin/comments/389437.html</wfw:comment><comments>http://www.blogjava.net/abin/archive/2012/10/11/389437.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/abin/comments/commentRss/389437.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/abin/services/trackbacks/389437.html</trackback:ping><description><![CDATA[<div style="padding: 1px 10px 5px; font-size: 13px; background-color: #f5f5f5; margin-top: 10px; margin-bottom: 10px; font-family: Verdana; line-height: 18px; "><div id="autotagbox">关键词：正则 oracle 数据库 web 开发 正则表达式 oracle正则表达式 regexp_like f REGEXP_SUBSTR 中文 oracle9 数据库正则表达式 数字 REGEXP_LIKE oracle表达式 10g中的正则表达式 oracle正則表達式 表达式 sql 正则表达式函数 百分号 转义字符 匹配 10g 使用正则表达式 oracle正则表达式regexp_like 正则替换 正则表达 字母数字组合 regexp_instr "/"的 ORACLE 语法 like 通配符 匹配中文 sql转义除号 POSIX正则表达式 oracle数据库表达式 转义符 regexp_substr $ replace函数 oralce正则表达式 oracle常用字符 转义 数字匹配 alnum 2233 REPLACE INTO oralce数字匹配 11g 子表达式 oralce 使用 0 REGEXP_REPLACE REGEXP_LIKE() 中文字符 字符串匹配 oracle，正则表达式 百分号的转义字符 单字符匹配 9 ORACLE转义 函数 replace 字母 正则表达式　数据库　匹配中文 關鍵 符號 分號 匹配单字符 REGEXP_INSTR sql中百分号 至少出现 匹配一部分内容</div><div id="summary">本文摘要：<br />10g正则表达式提高了SQL灵活性。<br />无关的空白检测，或者分解多个正则组成的字符串等问题。<br />10g支持正则表达式的四个新函数分别是：REGEXP_LIKE、REGEXP_INSTR、REGEXP_SUBSTR、和REGEXP_REPLACE。<br />正则表达式代替了老的百分号（%）和通配符（_）字符。<br />匹配输入字符串的开始位置，在方括号表达式中使用，此时它表示不接受该字符集合。<br />匹配前面的子表达式零次或一次。</div><div id="content">目前，正则表达式已经在很多软件中得到广泛的应用，包括*nix（Linux, Unix等），HP等操作系统，PHP，C#，Java等开发环境。<br /><br />Oracle 10g正则表达式提高了SQL灵活性。有效的解决了数据有效性， 重复词的辨认, 无关的空白检测，或者分解多个正则组成<br />的字符串等问题。<br /><br />Oracle 10g支持正则表达式的四个新函数分别是：REGEXP_LIKE、REGEXP_INSTR、REGEXP_SUBSTR、和REGEXP_REPLACE。<br />它们使用POSIX 正则表达式代替了老的百分号（%）和通配符（_）字符。<br /><br />特殊字符：<br />'^' 匹配输入字符串的开始位置，在方括号表达式中使用，此时它表示不接受该字符集合。<br />'$' 匹配输入字符串的结尾位置。如果设置了 RegExp 对象的 Multiline 属性，则 $ 也匹配 'n' 或 'r'。<br />'.' 匹配除换行符 n之外的任何单字符。<br />'?' 匹配前面的子表达式零次或一次。<br />'*' 匹配前面的子表达式零次或多次。<br />'+' 匹配前面的子表达式一次或多次。<br />'( )' 标记一个子表达式的开始和结束位置。<br />'[]' 标记一个中括号表达式。<br />'{m,n}' 一个精确地出现次数范围，m=&lt;出现次数&lt;=n，'{m}'表示出现m次，'{m,}'表示至少出现m次。<br />'|' 指明两项之间的一个选择。例子'^([a-z]+|[0-9]+)$'表示所有小写字母或数字组合成的字符串。<br />num 匹配 num，其中 num 是一个正整数。对所获取的匹配的引用。<br />正则表达式的一个很有用的特点是可以保存子表达式以后使用， 被称为Backreferencing. 允许复杂的替换能力<br />如调整一个模式到新的位置或者指示被代替的字符或者单词的位置. 被匹配的子表达式存储在临时缓冲区中，<br />缓冲区从左到右编号, 通过数字符号访问。 下面的例子列出了把名字 aa bb cc 变成<br />cc, bb, aa.<br />Select REGEXP_REPLACE('aa bb cc','(.*) (.*) (.*)', '3, 2, 1') FROM dual；<br />REGEXP_REPLACE('ELLENHILDISMIT<br />cc, bb, aa<br />'' 转义符。<br /><br />字符簇：<br />[[:alpha:]] 任何字母。<br />[[:digit:]] 任何数字。<br />[[:alnum:]] 任何字母和数字。<br />[[:space:]] 任何白字符。<br />[[:upper:]] 任何大写字母。<br />[[:lower:]] 任何小写字母。<br />[[:punct:]] 任何标点符号。<br />[[:xdigit:]] 任何16进制的数字，相当于[0-9a-fA-F]。<br /><br />各种操作符的运算优先级<br />转义符<br />(), (?:), (?=), [] 圆括号和方括号<br />*, +, ?, {n}, {n,}, {n,m} 限定符<br />^, $, anymetacharacter 位置和顺序<br />| &#8220;或&#8221;操作<br /><br />--测试数据<br />create table test(mc varchar2(60));<br /><br />insert into test values('112233445566778899');<br />insert into test values('22113344 5566778899');<br />insert into test values('33112244 5566778899');<br />insert into test values('44112233 5566 778899');<br />insert into test values('5511 2233 4466778899');<br />insert into test values('661122334455778899');<br />insert into test values('771122334455668899');<br />insert into test values('881122334455667799');<br />insert into test values('991122334455667788');<br />insert into test values('aabbccddee');<br />insert into test values('bbaaaccddee');<br />insert into test values('ccabbddee');<br />insert into test values('ddaabbccee');<br />insert into test values('eeaabbccdd');<br />insert into test values('ab123');<br />insert into test values('123xy');<br />insert into test values('007ab');<br />insert into test values('abcxy');<br />insert into test values('The final test is is is how to find duplicate words.');<br /><br />commit;<br /><br />一、REGEXP_LIKE<br /><br />select * from test where regexp_like(mc,'^a{1,3}');<br />select * from test where regexp_like(mc,'a{1,3}');<br />select * from test where regexp_like(mc,'^a.*e$');<br />select * from test where regexp_like(mc,'^[[:lower:]]|[[:digit:]]');<br />select * from test where regexp_like(mc,'^[[:lower:]]');<br />Select mc FROM test Where REGEXP_LIKE(mc,'[^[:digit:]]');<br />Select mc FROM test Where REGEXP_LIKE(mc,'^[^[:digit:]]');<br /><br />二、REGEXP_INSTR<br /><br />Select REGEXP_INSTR(mc,'[[:digit:]]$') from test;<br />Select REGEXP_INSTR(mc,'[[:digit:]]+$') from test;<br />Select REGEXP_INSTR('The price is $400.','$[[:digit:]]+') FROM DUAL;<br />Select REGEXP_INSTR('onetwothree','[^[[:lower:]]]') FROM DUAL;<br />Select REGEXP_INSTR(',,,,,','[^,]*') FROM DUAL;<br />Select REGEXP_INSTR(',,,,,','[^,]') FROM DUAL;<br /><br />三、REGEXP_SUBSTR<br /><br />SELECT REGEXP_SUBSTR(mc,'[a-z]+') FROM test;<br />SELECT REGEXP_SUBSTR(mc,'[0-9]+') FROM test;<br />SELECT REGEXP_SUBSTR('aababcde','^a.*b') FROM DUAL;<br /><br />四、REGEXP_REPLACE<br /><br />Select REGEXP_REPLACE('Joe Smith','( ){2,}', ',') AS RX_REPLACE FROM dual;<br />Select REGEXP_REPLACE('aa bb cc','(.*) (.*) (.*)', '3, 2, 1') FROM dual；<br /><br />SQL&gt; select * from test;<br /><br />ID MC<br />-------------------- ------------------------------------------------------------<br />A AAAAA<br />a aaaaa<br />B BBBBB<br />b bbbbb<br /><br />SQL&gt; select * from test where regexp_like(id,'b','i'); --不区分数据大小写<br /><br />ID MC<br />-------------------- ------------------------------------------------------------<br />B BBBBB<br />b bbbbb<br /><br />#End</div></div><img src ="http://www.blogjava.net/abin/aggbug/389437.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/abin/" target="_blank">abing</a> 2012-10-11 20:58 <a href="http://www.blogjava.net/abin/archive/2012/10/11/389437.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Oracle正则表达式的用法</title><link>http://www.blogjava.net/abin/archive/2012/10/11/389435.html</link><dc:creator>abing</dc:creator><author>abing</author><pubDate>Thu, 11 Oct 2012 12:06:00 GMT</pubDate><guid>http://www.blogjava.net/abin/archive/2012/10/11/389435.html</guid><wfw:comment>http://www.blogjava.net/abin/comments/389435.html</wfw:comment><comments>http://www.blogjava.net/abin/archive/2012/10/11/389435.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/abin/comments/commentRss/389435.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/abin/services/trackbacks/389435.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: l&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;方括号表达示方括号表达式描述[[:alnum:]]字母和数字混合的字符[[:alpha:]]字母字符[[:cntrl:]]控制字符[[:digit:]]数字字符[[:graph:]]图像字符[[:lower:]]小写字母字符[[:print:]]打印字符[[:punct：]]标点符号字符[[:spac...&nbsp;&nbsp;<a href='http://www.blogjava.net/abin/archive/2012/10/11/389435.html'>阅读全文</a><img src ="http://www.blogjava.net/abin/aggbug/389435.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/abin/" target="_blank">abing</a> 2012-10-11 20:06 <a href="http://www.blogjava.net/abin/archive/2012/10/11/389435.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>oracle replace translate</title><link>http://www.blogjava.net/abin/archive/2012/10/11/389433.html</link><dc:creator>abing</dc:creator><author>abing</author><pubDate>Thu, 11 Oct 2012 11:55:00 GMT</pubDate><guid>http://www.blogjava.net/abin/archive/2012/10/11/389433.html</guid><wfw:comment>http://www.blogjava.net/abin/comments/389433.html</wfw:comment><comments>http://www.blogjava.net/abin/archive/2012/10/11/389433.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/abin/comments/commentRss/389433.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/abin/services/trackbacks/389433.html</trackback:ping><description><![CDATA[<p><p><span style="font-size: small"><strong>简要比较：</strong></span></p> <p><span style="font-size: x-small">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: small">  replace 字符串级别的代替</span></p> <p><span style="font-size: small">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如：SELECT REPLACE('accd','cd','ef') from  dual; --&gt; aefd</span></p> <p>&nbsp;</p> <p><span style="font-size: small">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;translate 字符级别的代替</span></p> <p><span style="font-size: small">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如：select translate('acdd','cd','ef') from  dual; --&gt;aeff</span></p><br />replace（'将要更改的字符串','被替换掉的字符串','替换字符串'）</p> <p>例：select &nbsp;replace ('111222333444','222','888') from dual;</p> <p>输出为 '111888333444'<br /><br /><br /><p><span style="font-size: small"><strong>分别详解</strong></span></p> <p><span style="font-size: small">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>replace：</strong></span></p> <p><span style="font-size: small">&nbsp;&nbsp;&nbsp;&nbsp;  语法：REPLACE(char,search_string[,replacement_string])</span></p> <p><span style="font-size: small">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;解释：replace中，每个search_string都被replacement_string所代替</span></p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-size: small">select replace('acdd','cd','ef') from  dual; --&gt; aefd</span></p> <p>&nbsp;</p> <p><span style="font-size: small">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如果replacement_string为空或为null，那么所有的search_string都被移除</span></p> <p><span style="font-size: small">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;select replace('acdd','cd','') from dual;  --&gt; ad</span></p> <p>&nbsp;</p> <p><span style="font-size: small">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如果search_string  为null，那么就返回原来的char</span></p> <p><span style="font-size: small">&nbsp;&nbsp;&nbsp;&nbsp; select replace('acdd','ef') from dual;  --&gt;acdd</span></p> <p><span style="font-size: small">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;select replace('acdd','','') from dual;  --&gt;acdd(也是两者都为空的情况)</span></p> <p>&nbsp;</p> <p>&nbsp;</p> <p><span style="font-size: small">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong>translate:</strong></span></p> <p><span style="font-size: small">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  语法：TRANSLATE('char','from_string','to_string')</span></p> <p><span style="font-size: small">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;解释：translate中，每个from_string中的字符被to_string中</span></p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-size: small">&nbsp;&nbsp;举例说明：</span></p><br /><div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;select translate('asd12fg','12','55') from dual</div></p><img src ="http://www.blogjava.net/abin/aggbug/389433.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/abin/" target="_blank">abing</a> 2012-10-11 19:55 <a href="http://www.blogjava.net/abin/archive/2012/10/11/389433.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>oracle substr</title><link>http://www.blogjava.net/abin/archive/2012/10/11/389422.html</link><dc:creator>abing</dc:creator><author>abing</author><pubDate>Thu, 11 Oct 2012 09:49:00 GMT</pubDate><guid>http://www.blogjava.net/abin/archive/2012/10/11/389422.html</guid><wfw:comment>http://www.blogjava.net/abin/comments/389422.html</wfw:comment><comments>http://www.blogjava.net/abin/archive/2012/10/11/389422.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/abin/comments/commentRss/389422.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/abin/services/trackbacks/389422.html</trackback:ping><description><![CDATA[<p>oracle的substr函数的用法<br /><img alt="" align="top" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" />&nbsp;取得字符串中指定起始位置和长度的字符串&nbsp;&nbsp;&nbsp;substr(&nbsp;string,&nbsp;start_position,&nbsp;<span style="color: #ff0000">[</span><span style="color: #ff0000">&nbsp;length&nbsp;</span><span style="color: #ff0000">]</span>&nbsp;)<br /><img alt="" align="top" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" />&nbsp;如:<br /><img alt="" align="top" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;substr(<span style="color: #ff0000">'</span><span style="color: #ff0000">This&nbsp;is&nbsp;a&nbsp;test</span><span style="color: #ff0000">'</span>,&nbsp;<span style="color: #800000; font-weight: bold">6</span>,&nbsp;<span style="color: #800000; font-weight: bold">2</span>)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;would&nbsp;<span style="color: #0000ff">return</span>&nbsp;<span style="color: #ff0000">'</span><span style="color: #ff0000">is</span><span style="color: #ff0000">'</span><br /><img alt="" align="top" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;substr(<span style="color: #ff0000">'</span><span style="color: #ff0000">This&nbsp;is&nbsp;a&nbsp;test</span><span style="color: #ff0000">'</span>,&nbsp;<span style="color: #800000; font-weight: bold">6</span>)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;would&nbsp;<span style="color: #0000ff">return</span>&nbsp;<span style="color: #ff0000">'</span><span style="color: #ff0000">is&nbsp;a&nbsp;test</span><span style="color: #ff0000">'</span><br /><img alt="" align="top" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;substr(<span style="color: #ff0000">'</span><span style="color: #ff0000">TechOnTheNet</span><span style="color: #ff0000">'</span>,&nbsp;<span style="color: #808080">-</span><span style="color: #800000; font-weight: bold">3</span>,&nbsp;<span style="color: #800000; font-weight: bold">3</span>)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;would&nbsp;<span style="color: #0000ff">return</span>&nbsp;<span style="color: #ff0000">'</span><span style="color: #ff0000">Net</span><span style="color: #ff0000">'</span><br /><img alt="" align="top" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;substr(<span style="color: #ff0000">'</span><span style="color: #ff0000">TechOnTheNet</span><span style="color: #ff0000">'</span>,&nbsp;<span style="color: #808080">-</span><span style="color: #800000; font-weight: bold">6</span>,&nbsp;<span style="color: #800000; font-weight: bold">3</span>)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;would&nbsp;<span style="color: #0000ff">return</span>&nbsp;<span style="color: #ff0000">'</span><span style="color: #ff0000">The</span><span style="color: #ff0000">'</span></p> <p>&nbsp;&nbsp;select substr('Thisisatest', -4, 2)  value from dual&nbsp;&nbsp;&nbsp;&nbsp;结果是&nbsp;&nbsp;<span style="color: #ff0000"> te</span></p> <p>select substr('emros',-3,1) value from dual&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;结果是 <span style="color: #ff0000">r</span></p> <p>&nbsp;</p> <p><span id="comment_body_1430588">substr('abcde',-6) =  null <br />substr('abcde',-5) = 'abcde' <br />substr('abcde',-4) = 'bcde'  <br />substr('abcde',-3) = 'cde' <br />substr('abcde',-2) = 'de'  <br />substr('abcde',-1) = 'e' <br /><span style="color: #ff00ff">substr('abcde',-0)  = 'abcde'</span></span></p><img src ="http://www.blogjava.net/abin/aggbug/389422.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/abin/" target="_blank">abing</a> 2012-10-11 17:49 <a href="http://www.blogjava.net/abin/archive/2012/10/11/389422.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>oracle instr</title><link>http://www.blogjava.net/abin/archive/2012/10/11/389421.html</link><dc:creator>abing</dc:creator><author>abing</author><pubDate>Thu, 11 Oct 2012 09:46:00 GMT</pubDate><guid>http://www.blogjava.net/abin/archive/2012/10/11/389421.html</guid><wfw:comment>http://www.blogjava.net/abin/comments/389421.html</wfw:comment><comments>http://www.blogjava.net/abin/archive/2012/10/11/389421.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/abin/comments/commentRss/389421.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/abin/services/trackbacks/389421.html</trackback:ping><description><![CDATA[INSTR  <p>　　(源字符串, 目标字符串, 起始位置, 匹配序号)</p> <p>　　在<a href="http://oracle.chinaitlab.com/" rel="nofollow" target="_blank">Oracle</a>/PLSQL中，instr函数返回要截取的字符串在源字符串中的位置。只检索一次，就是说从字符的开始</p> <p>　　到字符的结尾就结束。</p> <p>　　语法如下：</p> <p>　　instr( string1, string2 [, start_position [, nth_appearance ] ] )</p> <p>　　参数分析：</p> <p>　　string1</p> <p>　　源字符串，要在此字符串中查找。</p> <p>　　string2</p> <p>　　要在string1中查找的字符串.</p> <p>　　start_position</p> <p>　　代表string1 的哪个位置开始查找。此参数可选，如果省略默认为1.  字符串索引从1开始。如果此参数为正，从左到右开始检索，如果此参数为负，从右到左检索，返回要查找的字符串在源字符串中的开始索引。</p> <p>　　nth_appearance</p> <p>　　代表要查找第几次出现的string2. 此参数可选，如果省略，默认为 1.如果为负数系统会报错。</p> <p>　　注意：</p> <p>　　如果String2在String1中没有找到，instr函数返回0.<br /><br /><br /><br />示例如下：<br /><div>select instr('adsda','a') from dual</div><div>select instr('adsda','a',1,2) from dual</div><div>select instr('adsda','a',-1,2) from dual</div><br /><br /><br /><br /><br /><br /></p><img src ="http://www.blogjava.net/abin/aggbug/389421.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/abin/" target="_blank">abing</a> 2012-10-11 17:46 <a href="http://www.blogjava.net/abin/archive/2012/10/11/389421.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>oracle regexp_like介绍和例子</title><link>http://www.blogjava.net/abin/archive/2012/10/11/389418.html</link><dc:creator>abing</dc:creator><author>abing</author><pubDate>Thu, 11 Oct 2012 09:37:00 GMT</pubDate><guid>http://www.blogjava.net/abin/archive/2012/10/11/389418.html</guid><wfw:comment>http://www.blogjava.net/abin/comments/389418.html</wfw:comment><comments>http://www.blogjava.net/abin/archive/2012/10/11/389418.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/abin/comments/commentRss/389418.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/abin/services/trackbacks/389418.html</trackback:ping><description><![CDATA[<p>ORACLE中的支持正则表达式的函数主要有下面四个：<br />1，REGEXP_LIKE ：与LIKE的功能相似<br />2，REGEXP_INSTR  ：与INSTR的功能相似<br />3，REGEXP_SUBSTR ：与SUBSTR的功能相似<br />4，REGEXP_REPLACE  ：与REPLACE的功能相似<br />它们在用法上与Oracle SQL 函数LIKE、INSTR、SUBSTR 和REPLACE  用法相同，<br />但是它们使用POSIX 正则表达式代替了老的百分号（%）和通配符（_）字符。<br />POSIX  正则表达式由标准的元字符（metacharacters）所构成：<br />'^'  匹配输入字符串的开始位置，在方括号表达式中使用，此时它表示不接受该字符集合。<br />'$' 匹配输入字符串的结尾位置。如果设置了 RegExp 对象的  Multiline 属性，则 $ 也匹<br />配 '\n' 或 '\r'。<br />'.' 匹配除换行符之外的任何单字符。<br />'?'  匹配前面的子表达式零次或一次。<br />'+' 匹配前面的子表达式一次或多次。<br />'*' 匹配前面的子表达式零次或多次。<br />'|'  指明两项之间的一个选择。例子'^([a-z]+|[0-9]+)$'表示所有小写字母或数字组合成的<br />字符串。<br />'( )'  标记一个子表达式的开始和结束位置。<br />'[]' 标记一个中括号表达式。<br />'{m,n}'  一个精确地出现次数范围，m=&lt;出现次数&lt;=n，'{m}'表示出现m次，'{m,}'表示至少<br />出现m次。<br />\num 匹配 num，其中  num 是一个正整数。对所获取的匹配的引用。<br />字符簇： <br />[[:alpha:]] 任何字母。<br />[[:digit:]]  任何数字。<br />[[:alnum:]] 任何字母和数字。<br />[[:space:]] 任何白字符。<br />[[:upper:]]  任何大写字母。<br />[[:lower:]] 任何小写字母。<br />[[:punct:]] 任何标点符号。<br />[[:xdigit:]]  任何16进制的数字，相当于[0-9a-fA-F]。<br />各种操作符的运算优先级<br />\转义符<br />(), (?:), (?=), []  圆括号和方括号<br />*, +, ?, {n}, {n,}, {n,m} 限定符<br />^, $, anymetacharacter 位置和顺序<br />|  <br />*/<br />--创建表<br />create table fzq<br />(<br />id varchar(4),<br />value  varchar(10)<br />);<br />--数据插入<br />insert into fzq  values<br />('1','1234560');<br />insert into fzq  values<br />('2','1234560');<br />insert into fzq  values<br />('3','1b3b560');<br />insert into fzq values<br />('4','abc');<br />insert  into fzq values<br />('5','abcde');<br />insert into fzq  values<br />('6','ADREasx');<br />insert into fzq values<br />('7','123  45');<br />insert into fzq values<br />('8','adc de');<br />insert into fzq  values<br />('9','adc,.de');<br />insert into fzq values<br />('10','1B');<br />insert  into fzq values<br />('10','abcbvbnb');<br />insert into fzq  values<br />('11','11114560');<br />insert into fzq  values<br />('11','11124560');<br />--regexp_like<br />--查询value中以1开头60结束的记录并且长度是7位<br />select  * from fzq where value like '1____60';<br />select * from fzq where  regexp_like(value,'1....60');<br />--查询value中以1开头60结束的记录并且长度是7位并且全部是数字的记录。<br />--使用like就不是很好实现了。<br />select  * from fzq where regexp_like(value,'1[0-9]{4}60');<br />--  也可以这样实现，使用字符集。<br />select * from fzq where  regexp_like(value,'1[[:digit:]]{4}60');<br />-- 查询value中不是纯数字的记录<br />select * from  fzq where not regexp_like(value,'^[[:digit:]]+$');<br />--  查询value中不包含任何数字的记录。<br />select * from fzq where  regexp_like(value,'^[^[:digit:]]+$');<br />--查询以12或者1b开头的记录.不区分大小写。<br />select *  from fzq where  regexp_like(value,'^1[2b]','i');<br />--查询以12或者1b开头的记录.区分大小写。<br />select * from fzq  where regexp_like(value,'^1[2B]');<br />-- 查询数据中包含空白的记录。<br />select * from fzq  where regexp_like(value,'[[:space:]]');<br />--查询所有包含小写字母或者数字的记录。<br />select * from  fzq where regexp_like(value,'^([a-z]+|[0-9]+)$');<br />--查询任何包含标点符号的记录。<br />select  * from fzq where regexp_like(value,'[[:punct:]]');</p> <p>例子：判断姓名是否为空，少于两个字符，包含数字和字母</p> <p>create or replace<br />FUNCTION CheckName(NameStr in VARCHAR2) RETURN  integer<br />As<br />BEGIN<br />--符合返回1，不符合返回0<br />&nbsp;&nbsp; if(NameStr is null or  length(NameStr)&lt;2) then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 0;<br />&nbsp;&nbsp; else<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(NameStr  like '%未取名%') then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RETURN 0;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end if;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if  regexp_like(NameStr,'^([a-z]+|[0-9]+|[A-Z]+)$') then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return  0;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end if; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp; end if;<br />END  CheckName;</p><img src ="http://www.blogjava.net/abin/aggbug/389418.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/abin/" target="_blank">abing</a> 2012-10-11 17:37 <a href="http://www.blogjava.net/abin/archive/2012/10/11/389418.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Oracle正则表达式(一)</title><link>http://www.blogjava.net/abin/archive/2012/10/11/389413.html</link><dc:creator>abing</dc:creator><author>abing</author><pubDate>Thu, 11 Oct 2012 09:09:00 GMT</pubDate><guid>http://www.blogjava.net/abin/archive/2012/10/11/389413.html</guid><wfw:comment>http://www.blogjava.net/abin/comments/389413.html</wfw:comment><comments>http://www.blogjava.net/abin/archive/2012/10/11/389413.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/abin/comments/commentRss/389413.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/abin/services/trackbacks/389413.html</trackback:ping><description><![CDATA[<p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; "><p>需求：</p><p>匹配手机号，第一位可以是+，可以没有+，后面的全部要是数字，如：</p><p>+861359415665</p><p>8613659558555</p><p>1356856455</p><p>都是合法的。</p>+aa156945555</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">aa1359556666</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">aaddssdfdfsd</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">都是不合法的。</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">正则：</p><div bg_sql"="" style="word-wrap: break-word; font-family: tahoma, 宋体; line-height: 22px; color: #333333; background-color: #efefef; "><div style="word-wrap: break-word; line-height: 1.6; "><div style="word-wrap: break-word; line-height: 1.6; "><strong>[sql]</strong></div></div><ol><li>SQL&gt;&nbsp;<strong>SELECT</strong>&nbsp;*&nbsp;<strong>FROM</strong>&nbsp;DUAL&nbsp;<strong>WHERE</strong>&nbsp;regexp_like('+333333'&nbsp;,'^[\+]*[[:digit:]]+');&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--该+转义或者不转义，结果是一样的&nbsp;&nbsp;&nbsp;</li><li>&nbsp;&nbsp;</li><li>DUMMY&nbsp;&nbsp;</li><li>-----&nbsp;&nbsp;&nbsp;</li><li>X&nbsp;&nbsp;</li></ol></div><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; "><strong>[sql]</strong></p><div bg_sql"="" style="word-wrap: break-word; font-family: tahoma, 宋体; line-height: 22px; color: #333333; background-color: #efefef; "><ol><li>SQL&gt;&nbsp;<strong>SELECT</strong>&nbsp;*&nbsp;<strong>FROM</strong>&nbsp;DUAL&nbsp;<strong>WHERE</strong>&nbsp;regexp_like('aa333333'&nbsp;,'^[+]*[[:digit:]]+');&nbsp;&nbsp;</li><li>&nbsp;&nbsp;</li><li>DUMMY&nbsp;&nbsp;</li><li>-----&nbsp;&nbsp;</li></ol></div><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">解释：</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">1.^代表开始，*表示出现0次或多次，+表示出现1次或多次，[:digit:]代表0-9的纯数字（还有$代表以什么结尾，如果是[[:digit:]]+$代表以数字结尾）。该正则的意思就是：</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">以+0次或多次开头，紧接着后面数字出现一次或多次（即一定要有数字）。</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">2.dual表中，永远只有1行记录。查询出dual中有记录，证明where条件成立，反之不成立。</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">先前写了一个错误的正则：</p><div bg_sql"="" style="word-wrap: break-word; font-family: tahoma, 宋体; line-height: 22px; color: #333333; background-color: #efefef; "><div style="word-wrap: break-word; line-height: 1.6; "><div style="word-wrap: break-word; line-height: 1.6; "><strong>[sql]</strong></div></div><ol><li>[\+]*[[:digit:]]+&nbsp;&nbsp;</li></ol></div><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">注意，就只少了一个代表开始符号的^。少了这个符号，说明这个正则的意思是：</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">+出现0次或多次（即+可以出现，可以不出现！！），紧后面的数字出现1次或多次。前面已经+可以出现0次了，证明没有+也可以，那么就是只要字符串中有数字(+aa111a，aass11111&#8230;&#8230;)，这个正则恒成立，错误深重啊！！<br /></p><p align="center" style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; "><span style="font-size: 18px; background-color: #33ff33; "><a href="http://www.linuxidc.com/topicnews.aspx?tid=12" target="_blank" title="Oracle" style="color: #b32bd5; ">Oracle</a>正则表达式的应用by 温州--名次</span></p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">在oracle里正则表达式有四个函数可用，分别是regexp_like、regexp_substr、regexp_instr 和regexp_replace。这里在我们oracle 10g里灵活应用。</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 先来简单介绍一下正则表达式的内容，正则表达式是做为快速查询的文本内容的，在linux应用比较多，首先，行的起始与结束 &#8220;^&#8221;这个字符是表示只查找行首的内容。&#8220;$&#8221;这个字符只查找行末的内容。接下来是&#8220;^&#8221;还可以做为一个排除字符来使用。还是使用例子来做一个演示比较明了一下。</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这里我使用regexp_like这个函数来做，这样可以我们平时会使用的比较多。</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">select * from test_table</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">where regexp_like(field_1,'^1234')</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">这个就是表示是以1234打头的字符串是不是有匹配的。这里和like的方式是一样的。</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">select * from test_table</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">where regexp_like(field_1,'^[12]234')</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">这里多了一个[]这里做一个独立字符，这里表示是以1或2开始，并且接着是234这个里的字符就会是匹配的。</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">select * from test_table</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">where regexp_like(field_1,'^(欧阳|李)小二')</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">这里我们就可以表达，这个查询一个姓是欧阳或李的，名字叫小二的字符串。这里多了一个（）这个是做一个为字符串的方式来写的与[]刚好是对应。</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">这里还有一个&#8220;|&#8221;来表示或的意思。</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">select * from test_table</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">where regexp_like(field_1,'^李[小]*二')</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">这里我们就可以查询李小二或是李二，再或者是李小小二，都可以，这里我们需要讲一下是[]后面带了一个*，这个是表示0~无穷大 字符去匹配。这个[]我们还可以添加一个&#8220;+&#8221;来表示1~无穷大的字符去匹配，也可以更加精准一些，在[]后面{1,3}这里就是表示1个到3个相同字符的匹配。还有一个&#8220;?&#8221;来说表示1或是0个。</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">select * from test_table</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">where regexp_like(field_1,'李[^小]二')</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">这里我们可以查询到姓李的，但是第二字不是&#8220;小&#8221;这个字。</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">select * from test_table</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">where regexp_like(field_1,'[0-9]')</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">这里是表示我们查询字符串含有0-9的数字的字符串。</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">select * from test_table</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">where regexp_like(field_1,'[a-z]')</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">这里是表示我们查询字符串含有a-z的小写字母的字符串。</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">select * from test_table</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">where regexp_like(field_1,'[A-z]')</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">这里是表示我们查询字符串含有A-z的所有字母的字符串。</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">select * from test_table</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">where regexp_like(name,'[[:alpha:]]')</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">这里是表示查询匹配任意字母，也包括中文字</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">select * from test_table</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">where regexp_like(name,'[[:alnum:]]')</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">这里是表示查询匹配任意字母和数字</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">select * from test_table</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">where regexp_like(name,'[[:digit:]]')</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">这里是表示查询匹配任意数字</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">Select * from test_table</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">Where regexp_like(name,&#8217;of&#8217;,&#8217;i&#8217;)</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">这里就是of不区分大小写</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">Select * from test_table</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">Where regexp_like(name,&#8217;^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$&#8217;)</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">这样我们可以查询是不是ip格式</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">接下来介绍一下regexp_substr</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">这个也是一个非常实用的一个函数</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;REGEXP_SUBSTR与SUBSTR函数相同，返回截取的子字符串</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">REGEXP_SUBSTR(srcstr, pattern [, position [, occurrence [, match_option]]])</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">注：</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">srcstr 源字符串</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">pattern 正则表达式样式</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">position 开始匹配字符位置</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">occurrence 匹配出现次数</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">match_option 匹配选项（区分大小写）</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p align="left" style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">SELECT regexp_substr('1PSN/231_3253/ABc', '[[:alnum:]]+') FROM dual;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">Output: 1PSN</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">[[:alnum:]]+ 表示匹配1个或者多个字母或数字字符</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">SELECT regexp_substr('1PSN/231_3253/ABc', '[[:alnum:]]+', 1, 2) FROM dual;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">Output: 231</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">与上面一个例子相比，多了两个参数</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">1 表示从源字符串的第一个字符开始查找匹配</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">2 表示第2次匹配到的字符串（默认值是&#8220;1&#8221;，如上例）</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">select regexp_substr('@@/231_3253/ABc','@*[[:alnum:]]+') from dual;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">Output: 231</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">@* 表示匹配0个或者多个@</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">[[:alnum:]]+ 表示匹配1个或者多个字母或数字字符</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">注意：需要区别&#8220;+&#8221;和&#8220;*&#8221;的区别</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">select regexp_substr('1@/231_3253/ABc','@+[[:alnum:]]*') from dual;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">Output: @</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">@+ 表示匹配1个或者多个@</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">[[:alnum:]]* 表示匹配0个或者多个字母或数字字符</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">select regexp_substr('1@/231_3253/ABc','@+[[:alnum:]]+') from dual;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">Output: Null</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">@+ 表示匹配1个或者多个@</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">[[:alnum:]]+ 表示匹配1个或者多个字母或数字字符</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">select regexp_substr('@1PSN/231_3253/ABc125','[[:digit:]]+$') from dual;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">Output: 125</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">[[:digit:]]+$ 表示匹配1个或者多个数字结尾的字符</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">select regexp_substr('1@/231_3253/ABc','@+[[:alnum:]]+') from dual;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">Output: Null</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">@+ 表示匹配1个或者多个@</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">[[:alnum:]]+ 表示匹配1个或者多个字母或数字字符</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">select regexp_substr('@1PSN/231_3253/ABc125','[[:digit:]]+$') from dual;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">Output: 125</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">[[:digit:]]+$ 表示匹配1个或者多个数字结尾的字符</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">select regexp_substr('@1PSN/231_3253/ABc','[^[:digit:]]+$') from dual;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">Output: /ABc</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">[^[:digit:]]+$ 表示匹配1个或者多个不是数字结尾的字符</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">select regexp_substr('Tom_Kyte@oracle.com','[^@]+') from dual;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">Output: Tom_Kyte</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">[^@]+ 表示匹配1个或者多个不是&#8220;@&#8221;的字符</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">select regexp_substr('1PSN/231_3253/ABc','[[:alnum:]]*',1,2)</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">from dual;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">Output: Null</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">[[:alnum:]]* 表示匹配0个或者多个字母或者数字字符</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">注：因为是匹配0个或者多个，所以这里第2次匹配的是&#8220;/&#8221;（匹配了0次），而不是&#8220;231&#8221;，所以结果是&#8220;Null&#8221;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">这里我们有时候会查询字符串里asdfafd&lt;main&gt;dafda 这里我们要取出&lt;main&gt;这个字符串</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">Select regexp_substr('asdfafd&lt;main&gt;dafda','&lt;[^&gt;]+&gt;') from dual</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">Output: &lt;main&gt;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">这里我们在&lt;&gt;中间去一个^&gt;这样在匹配&lt;之后，在向后查询的时候确保在匹配到&gt;之前不再在有&gt;,不然的话就要有可以出错的情况。</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">Select regexp_substr('asdfafd&lt;main&gt;da&gt;fda','&lt;[^&lt;]+&gt;') from dual</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">Output: &lt;main&gt;da&gt;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">在这个例子中，我们在&lt;main&gt;之后还在da&gt;，这样的话，如果我们没有添加^&gt;，正则表达式就会向后继续去匹配，直到最后一个&gt;为至，这样就会出现偏差</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">这个通常用来实现字符串的列传行</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">select regexp_substr('123;234;345;456;567;678;789','[^;]+',1,rownum) from dual</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">connect by rownum &lt;= length('123;234;345;456;567;678;789') - length(replace('123;234;345;456;567;678;789',';'))+1</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">这里length这里操作是先得到有多少个&#8220;;&#8221;，再通过 connect by rownum方式来做一行成多行的操作，在变成多行之后，可以通过regexp_substr来取字符串的操作</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">接着上一个例子</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">a,b,c,d,e,d,f,a,n这样的一个字符串，我们现在要把字符串里一些重复去掉，这样的话结果是a,b,c,d,e,f,n去掉了d与a的两个字符串</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">select wm_concat(new_row) from (</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">select distinct regexp_substr('a,b,c,d,e,d,f,a,n','[^,]+',1,rownum) new_row from dual</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">connect by rownum&lt;=length('a,b,c,d,e,d,f,a,n')-length(replace('a,b,c,d,e,d,f,a,n',',')))</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">通过转成多行的，再用distinct 去掉重复，然后我们再通过wm_concat来字符串合并来完成。</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">再来一个ip格式转换的例子吧，我们一般的IP的格式是12.19.168.27现在要不足3位的补足前面为0，结果是012.019.168.027</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">select wm_concat(new_value) from (</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">select</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">lpad(regexp_substr('12.19.168.27','[^.]+',1,rownum) ,3,'0') new_value,rownum</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">from dual</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">connect by rownum&lt;5</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">order by rownum)</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">来一个验证IP是数字是否正确</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">select count(*) from(</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">select</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">lpad(regexp_substr('12.19.168.27','[^.]+',1,rownum) ,3,'0') new_value,rownum</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">from dual</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">connect by rownum&lt;5)</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">where new_value&gt;=0 and new_value&lt;256</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">having count(*) =4</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">来一个IP字符串格式转换成数字型IP</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">select sum(new_value*power(256,4-rm)) from (</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">select regexp_substr('12.19.168.27','[^.]+',1,rownum) new_value,rownum rm from dual</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">connect by rownum&lt;=4</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">)</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">接下来介绍一个regexp_instr函数</p><p align="left" style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">REGEXP_INSTR 函数使用正则表达式返回搜索模式的起点和终点。REGEXP_INSTR 的语法如下所示。REGEXP_INSTR 返回一个整数，指出搜索模式的开始或结束的位置，如果没有发现匹配的值，则返回0。</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">语法：</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">2.REGEXP_INSTR与INSTR函数相同，返回字符串位置</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">REGEXP_INSTR(srcstr, pattern [, position [, occurrence [, return_option [,match_option]]]])</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">与REGEXP_SUBSTR一样，它也有变量pattern、position(开始位置)、occurrence 和match_parameter；这里主要介绍一下新参数return_option 的作用，它允许用户告诉Oracle，模式出现的时候，要返回什么内容。</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">Select regexp_instr('asdfafd&lt;main&gt;da&gt;fda','sd') from dual</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">Output:2</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">这里去查询sd的位置，这个和instr是在相同的</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">Select regexp_instr('asdfafd&lt;main&gt;da&gt;fda','da',1,2) from dual</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">这里是查询da第二出现的位置</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">还有我们经常会遇到一种情况是，查询某个字段，如果是等于&#8220;上海&#8221;或&#8220;北京&#8221;或者我们温州就写成大城市，其它的写成小城市，我们一般会考虑使用decode这种方式</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">Select decode('上海','上海','大城市','北京' ,'大城市' ,'温州' ,'大城市','小城市') from dual</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">只有两个我们可能觉的sql也不是很冗长，如果有四五个的话，就有点长了，这里使用regexp_instr就可以很多的去操作</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">Select decode (regexp_instr('北京','^(上海|北京|温州)'),0,'小城市', '大城市') from dual</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">通过regexp_instr不匹配时为0的条件，这样就可以完成了</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">最后一个函数regexp_replace</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">REGEXP_REPLACE 函数是用另外一个值来替代串中的某个值。例如，可以用一个匹配数字来替代字母的每一次出现。REGEXP_REPLACE的格式如下所示</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">语法：</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">4.REGEXP_REPLACE与REPLACE函数相同，替换原字符串中的字符内容</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">REGEXP_REPLACE(srcstr, pattern [,replacestr [, position [, occurrence [,match_option]]]])</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">这个替换函数还是一个非常好用的。</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">如我们在有一个字符串adfadfa (main) next 现在我们要把()替换成&lt;&gt;，这里我们可能想用replace就可以搞定了，但是我们现在做的是(之后必须有)这样的()我们才替换把&lt;&gt;.</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">select regexp_replace('adfadfa (main) next ','(\()([^\)]*)(\))','&lt;\2&gt;') from dual</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">output: adfadfa &lt;main&gt; next</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">这里还是一个\做为转义字符。</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">再来一个ip格式转换的例子吧，我们一般的IP的格式是12.19.168.27现在要不足3位的补足前面为0，结果是012.019.168.027</p><p align="left" style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">select regexp_replace(</p><p align="left" style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">regexp_replace('12.19.168.27','([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3})',</p><p align="left" style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">'00\1.00\2.00\3.00\4') ,</p><p align="left" style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">'([0-9]*)([0-9]{3}\.)([0-9]*)([0-9]{3}\.)([0-9]*)([0-9]{3}\.)([0-9]*)([0-9]{3}$)','\2\4\6\8')</p><p align="left" style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">from dual</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">output: 012.019.168.027</p><p align="left" style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">这里我分成两步来操作，regexp_replace('12.19.168.27','([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3})',</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">'00\1.00\2.00\3.00\4')我首先让每个小字符串做添加0，这样每个字符串都会大于3，再</p><p align="left" style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">'([0-9]*)([0-9]{3}\.)([0-9]*)([0-9]{3}\.)([0-9]*)([0-9]{3}\.)([0-9]*)([0-9]{3}$)','\2\4\6\8')</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">这整个字符串分成8段，这样我们只要2、4、6、8这四个段就可以了。</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">下面一个例子中，在每两个字符之间插入一个空格符</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">SELECT regexp_replace('YAHOO', '(.)', '\1 ') AS output FROM dual;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">Output: Y A H O O</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">这个用一个循环的方式去操作，还蛮好的。</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">select regexp_replace(</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">regexp_replace('12.19.168.27','([^.]+)'</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">,'00\1')</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">,'([^.]*)([^.]{3})','\2')</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">from dual</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef; ">接着刚才那个，我们可以把replace循环替换的方式来操作。</p><img src ="http://www.blogjava.net/abin/aggbug/389413.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/abin/" target="_blank">abing</a> 2012-10-11 17:09 <a href="http://www.blogjava.net/abin/archive/2012/10/11/389413.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Oracle regex</title><link>http://www.blogjava.net/abin/archive/2012/10/11/389412.html</link><dc:creator>abing</dc:creator><author>abing</author><pubDate>Thu, 11 Oct 2012 09:03:00 GMT</pubDate><guid>http://www.blogjava.net/abin/archive/2012/10/11/389412.html</guid><wfw:comment>http://www.blogjava.net/abin/comments/389412.html</wfw:comment><comments>http://www.blogjava.net/abin/archive/2012/10/11/389412.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/abin/comments/commentRss/389412.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/abin/services/trackbacks/389412.html</trackback:ping><description><![CDATA[<div>正则表达式，给我写个1,2,3,4 或者4,1,2,3 &nbsp;&nbsp;匹配出4 来&nbsp;<br /><div>select regexp_substr('1,2,3,4','[4]') tony from dual;</div></div><div>select regexp_substr('4,3,2,1','[4]') tony from dual;<br />oracle &nbsp;验证电话号码(手机号码)：<br /><br /><div style="color: #333333; font-family: verdana, sans-serif; font-size: 13px; line-height: 17px; background-color: #ffffff; ">/**</div><div style="color: #333333; font-family: verdana, sans-serif; font-size: 13px; line-height: 17px; background-color: #ffffff; "><span style="white-space: pre; ">	</span>&nbsp;* 手机号码</div><div style="color: #333333; font-family: verdana, sans-serif; font-size: 13px; line-height: 17px; background-color: #ffffff; "><span style="white-space: pre; ">	</span>&nbsp;* 移动：134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188</div><div style="color: #333333; font-family: verdana, sans-serif; font-size: 13px; line-height: 17px; background-color: #ffffff; "><span style="white-space: pre; ">	</span>&nbsp;* 联通：130,131,132,152,155,156,185,186</div><div style="color: #333333; font-family: verdana, sans-serif; font-size: 13px; line-height: 17px; background-color: #ffffff; "><span style="white-space: pre; ">	</span>&nbsp;* 电信：133,1349,153,180,189</div><div style="color: #333333; font-family: verdana, sans-serif; font-size: 13px; line-height: 17px; background-color: #ffffff; "><span style="white-space: pre; ">	</span>&nbsp;*/</div><div>select t.* from myregex t where regexp_like(t.name,'^1(3[0-9]|5[0-35-9]|8[025-9])[0-9]{8}$')<br /><div>select t.* from myregex t where regexp_like(t.name,'^1(3[0-9]|5[0-35-9]|8[025-9])?[0-9]{8}?$')<br /><div>select t.* from myregex t where regexp_like(t.name,'^1(3[[:digit:]]|5[0-35-9]|8[025-9])?[[:digit:]]{8}?$')<br /><div style="color: #333333; font-family: verdana, sans-serif; font-size: 13px; line-height: 17px; background-color: #ffffff; ">/**</div><div style="color: #333333; font-family: verdana, sans-serif; font-size: 13px; line-height: 17px; background-color: #ffffff; "><span style="white-space: pre; ">	</span>&nbsp;* 中国移动：China Mobile</div><div style="color: #333333; font-family: verdana, sans-serif; font-size: 13px; line-height: 17px; background-color: #ffffff; "><span style="white-space: pre; ">	</span>&nbsp;* 134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188</div><div style="color: #333333; font-family: verdana, sans-serif; font-size: 13px; line-height: 17px; background-color: #ffffff; "><span style="white-space: pre; ">	</span>&nbsp;*/<br /><div>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}$')<br /><div>select t.* from myregex t where regexp_like(t.name,'^1(34[0-8]?|3[5-9]?|5[017-9]?|8[278]?)[[:digit:]]{8}$')<br /><div>/**</div><div><span style="white-space: pre; ">	</span>&nbsp;* 中国联通：China Unicom</div><div><span style="white-space: pre; ">	</span>&nbsp;* 130,131,132,152,155,156,185,186</div><div><span style="white-space: pre; ">	</span>&nbsp;*/<br /><div>select t.* from myregex t where regexp_like(t.name,'^1(3[0-2]?|5[25-6]?|8[5-6]?)[0-9]{8}$')</div><div>select t.* from myregex t where regexp_like(t.name,'^1(3[0-2]?|5[25-6]?|8[5-6]?)[[:digit:]]{8}$')<br /><div>/**</div><div><span style="white-space: pre; ">	</span>&nbsp;* 中国电信：China Telecom</div><div><span style="white-space: pre; ">	</span>&nbsp;* 133,1349,153,180,189</div><div><span style="white-space: pre; ">	</span>&nbsp;*/</div><div>select t.* from myregex t where regexp_like(t.name,'^1((33?|53?|8[09]?)[0-9]?|349)[0-9]{7}$')</div></div></div><div>select t.* from myregex t where regexp_like(t.name,'^1((33?|53?|8[09]?)[0-9]?|349)[[:digit:]]{7}$')</div></div></div><br /></div><br /></div></div></div></div><img src ="http://www.blogjava.net/abin/aggbug/389412.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/abin/" target="_blank">abing</a> 2012-10-11 17:03 <a href="http://www.blogjava.net/abin/archive/2012/10/11/389412.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Oracle NVL NVL2 NULLIF</title><link>http://www.blogjava.net/abin/archive/2012/10/11/389376.html</link><dc:creator>abing</dc:creator><author>abing</author><pubDate>Thu, 11 Oct 2012 05:58:00 GMT</pubDate><guid>http://www.blogjava.net/abin/archive/2012/10/11/389376.html</guid><wfw:comment>http://www.blogjava.net/abin/comments/389376.html</wfw:comment><comments>http://www.blogjava.net/abin/archive/2012/10/11/389376.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/abin/comments/commentRss/389376.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/abin/services/trackbacks/389376.html</trackback:ping><description><![CDATA[<pre id="best-answer-content"  mb10"="" data-accusearea="aContent" style="margin-top: 0px; margin-bottom: 10px; padding: 0px; font-family: Arial; white-space: pre-wrap; word-wrap: break-word; zoom: 1; line-height: 22px; background-color: #fffcf6; ">NULL指的是空值，或者非法值。<br /> NVL (expr1, expr2)-&gt;expr1为NULL，返回expr2；不为NULL，返回expr1。注意两者的类型要一致 <br />NVL2 (expr1, expr2, expr3) -&gt;expr1不为NULL，返回expr2；为NULL，返回expr3。expr2和expr3类型不同的话，expr3会转换为expr2的类型 <br /><div>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')</div>NULLIF (expr1, expr2) -&gt;相等返回NULL，不等返回expr1<br /><div>select t.empno,nullif(t.mgr,'tom') from emp t where t.deptno in (select s.deptno from dept s where s.deptno='1')</div></pre><img src ="http://www.blogjava.net/abin/aggbug/389376.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/abin/" target="_blank">abing</a> 2012-10-11 13:58 <a href="http://www.blogjava.net/abin/archive/2012/10/11/389376.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>