oralce 字符串操作惯用函数
1、to_number 语法:TO_NUMBER(string[,format[,nlsparams]]) 在这只举一个简单的例子 select to_number('0023') from dual 结果为: ------ 23 2、lpad 在Oracle/PLSQL中,lpad函数将左边的字符串填充一些特定的字符,其语法格式如下: lpad( string1, padded_length, [ pad_string ] ) pad_string是个可选参数,这个字符串是要粘贴到string1的左边,如果这个参数未写,lpad函数将会在string1的左边粘贴空格。 将返回 'ztech on the net' 3、substr oracle的substr函数的用法 4、instr
目的:将CHAR或VARCHAR2类型的string转换为一个NUMBER类型的数值,如果指定了format,那么string应该遵循相应的数字格式。nlsparams的用来指定小数点和钱分位分隔符,以及货币符号。它与TO_CHAR()互为反函数
其中string1是需要粘贴字符的字符串
padded_length是返回的字符串的数量,如果这个数量比原字符串的长度要短,lpad函数将会把字符串截取成padded_length;
例如:
lpad('tech', 7);
将返回' tech'
lpad('tech', 2);
将返回'te'
lpad('tech', 8, '0');
将返回'0000tech'
lpad('tech on the net', 15, 'z');
将返回 'tech on the net'
lpad('tech on the net', 16, 'z');
取得字符串中指定起始位置和长度的字符串 substr( string, start_position, [ length ] )
如:
substr('This is a test', 6, 2) would return 'is'
substr('This is a test', 6) would return 'is a test'
substr('TechOnTheNet', -3, 3) would return 'Net'
substr('TechOnTheNet', -6, 3) would return 'The'
INSTR(源字符串, 目标字符串, 起始位置, 匹配序号)
例如:INSTR('CORPORATE FLOOR','OR', 3, 2)中,源字符串为'CORPORATE FLOOR', 目标字符串为'OR',起始位置为3,取第2个匹配项的位置。
默认查找顺序为从左到右。当起始位置为负数的时候,从右边开始查找。
所以SELECT INSTR('CORPORATE FLOOR', 'OR', -1, 1) "Instring" FROM DUAL的显示结果是
Instring
——————
14