码迷,mamicode.com
首页 > 数据库 > 详细

Oracle 【to_number】【instr】

时间:2016-05-25 20:20:25      阅读:298      评论:0      收藏:0      [点我收藏+]

标签:

需求:对一个包含数字的字符串排序

search后参考了  http://www.cnblogs.com/m-cnblogs/archive/2012/03/30/2425938.html

截屏:

(用到了to_number(str,split 1,...)   instr()  replace()  substr())

 

技术分享

 

TO_NUMBER(x [, format], [ nls_language ]) 

converts x to a NUMBER.

  • x is the string that will be converted to a number.
  • format, optional, is the format that will be used to convert x to a number.
  • nls_language, optional, is the nls language used to convert x to a number

INSTR(string, pattern-to-find)

INSTR returns the location (beginning) of a pattern in a given string. Its simple form is:

The general syntax of INSTR is:

INSTR (string to search, search pattern [, start [,occurrence]])

The arguments within brackets ([]) are optional.

在一个字符串中查找指定的字符,返回被查找到的指定的字符的位置。 

如果start的值为负数,则代表从右往左进行查找,但是位置数据仍然从左向右计算。 

SUBSTR retrieves a portion of the string. The general format for this function is:

SUBSTR(string, start_at_position[, number_of_characters_to_retrieve])  
从给定的字符表达式返回一个子字符串。    
REPLACE(source-string, pattern-to-find, pattern-to-replace-by)

(to)‘2011-10-11’  ‘2011/10/11’ 转换

update 表1 t set t.列1=replace((select 列1from 表1 a where a.主键列=t.主键列) , ‘/‘ , ‘-‘ ) 

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

输出为 ‘111888333444‘

最后我的代码

pn
to_number(str,’-’)

str:

replace(source ,’-’)

source:

substr(pn,instr(pn,’-’)+1,  length(pn)-1-instr(pn,’-’))

Oracle 【to_number】【instr】

标签:

原文地址:http://www.cnblogs.com/newcoder/p/5528103.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!