好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

oracle sql表联合报错invalid number,筛出字段中的数值集合

* from 表名 where nvl2(translate(字段名, ‘ /1234567890 ‘ , ‘ / ‘ ), ‘ CHAR ‘ , ‘ NUMBER ‘ ) = ‘ CHAR ‘

2.正则表达式函数 REGEXP_SUBSTR 处理,将数据进行过滤,ok!

 --  条件语句: 
 where   REGEXP_SUBSTR(t1.operatorid,  ‘  [0-9]+  ‘ )  IS   NOT   NULL 

 --  示例: 
 select  t1.operatorid,t2.equ_group,  max (last_login) last_login  from   表 t1,
(  select  t1.equ_group, t2.locationid  from   表 t1,表 t2
  where   t2.equ_id  =   t1.id)t2
  where  t1.eqpid =  t2.locationid
  and   REGEXP_SUBSTR(t1.operatorid,  ‘  [0-9]+  ‘ )  IS   NOT   NULL 
 group   by  t1.operatorid,t2.equ_group

3.扩展:

正则表达式函数 REGEXP_SUBSTR,有5个参数,分别是:

第一个是输入的字符串

第二个是正则表达式

第三个是标识从第几个字符开始正则表达式匹配。(默认为1)

第四个是标识第几个匹配组。(默认为1)

第五个是是取值范围:

  i:大小写不敏感;

  c:大小写敏感;

  n:点号 . 不匹配换行符号;

  m:多行模式;

  x:扩展模式,忽略正则表达式中的空白字符。

 --  example: 
 SELECT  REGEXP_SUBSTR( ‘  ABC123BCD456  ‘ , ‘  [0-9]+  ‘ )  FROM   DUAL;
  --  返回123 

 SELECT  REGEXP_SUBSTR( ‘  ABC123BCD456  ‘ , ‘  [0-9]+  ‘ , 6 )  FROM   DUAL;
  --  返回3 

 SELECT  REGEXP_SUBSTR( ‘  ABC123BCD456  ‘ , ‘  [0-9]+  ‘ , 7 )  FROM   DUAL;
  --  返回456 

 SELECT  REGEXP_SUBSTR( ‘  ABC123BCD456  ‘ , ‘  [0-9]+  ‘ , 1 , 2 )  FROM   DUAL;
  --  返回456 

translate函数,语法是TRANSLATE(string,from_str,to_str),其功能是返回将(所有出现的)from_str中的每个字符替换为to_str中的相应字符以后的string。

TRANSLATE 是 REPLACE 所提供的功能的一个超集。如果 from_str 比 to_str 长,
那么在 from_str 中而不在 to_str 中的额外字符将从 string 中被删除,因为它们没有相应的替换字符。to_str 不能为空。Oracle 将空字符串解释为 NULL,并且如果TRANSLATE
中的任何参数为NULL,那么结果也是 NULL。

 --  语法: 
 select  translate( ‘  字段  ‘  ,  ‘  0123456789  ‘   ||   ‘  字段  ‘  ,  ‘  0123456789  ‘ )  from   表;
  --  example: 
 select  translate( ‘  sdgub1235sdhau  ‘  , ‘  0123456789  ‘  ||  ‘  sdgub1235sdhau  ‘  , ‘  0123456789  ‘  ) 
  from   dual

  --  输出:  
--  1235 

 

oracle sql表联合报错invalid number,筛出字段中的数值集合

标签:bst   数据集   col   sql   abc   ||   ast   大小写   acl   

查看更多关于oracle sql表联合报错invalid number,筛出字段中的数值集合的详细内容...

  阅读:25次