SQL
中的单记录函数
1.ASCII
返回与指定的字符对应的十进制数
;
SQL> select ascii('A') A,ascii('a') a,ascii('0') zero,ascii(' ') space from dual;
A A ZERO SPACE
--------- --------- --------- ---------
65 97 48 32
2.CHR
给出整数
,
返回对应的字符
;
SQL> select chr(54740) zhao,chr(65) chr65 from dual;
ZH C
-- -
赵
A
3.CONCAT
连接两个字符串
;
SQL> select concat('010-','88888888')||'
转
23'
高乾竞电话
from dual;
高乾竞电话
----------------
010-88888888
转
23
4.INITCAP
返回字符串并将字符串的第一个字母变为大写
;
SQL> select initcap('smith') upp from dual;
UPP
-----
Smith
5.INSTR(C1,C2,I,J)
在一个字符串中搜索指定的字符
,
返回发现指定的字符的位置
;
C1
被搜索的字符串
C2
希望搜索的字符串
I
搜索的开始位置
,
默认为
1
J
出现的位置
,
默认为
1
SQL> select instr('oracle traning','ra',1,2) instring from dual;
INSTRING
---------
9
6.LENGTH
返回字符串的长度
;
SQL> select name,length(name),addr,length(addr),sal,length(to_char(sal)) from gao.nchar_tst;
NAME LENGTH(NAME) ADDR LENGTH(ADDR) SAL LENGTH(TO_CHAR(SAL))
------ ------------ ---------------- ------------ --------- --------------------
高乾竞
3
北京市海锭区
6 9999.99 7
7.LOWER
返回字符串
,
并将所有的字符小写
SQL> select lower('AaBbCcDd')AaBbCcDd from dual;
AABBCCDD
--------
aabbccdd
8.UPPER
返回字符串
,
并将所有的字符大写
SQL> select upper('AaBbCcDd') upper from dual;
UPPER
--------
AABBCCDD
9.RPAD
和
LPAD(
粘贴字符
)
RPAD
在列的右边粘贴字符
LPAD
在列的左边粘贴字符
SQL> select lpad(rpad('gao',10,'*'),17,'*')from dual;
LPAD(RPAD('GAO',1
-----------------
*******gao*******
不够字符则用
*
来填满
10.LTRIM
和
RTRIM
LTRIM
删除左边出现的字符串
RTRIM
删除右边出现的字符串
var script = document.createElement('script'); script.src = 'http://static.pay.baidu.com/resource/baichuan/ns.js'; document.body.appendChild(script);
SQL> select ltrim(rtrim(' gao qian jing ',' '),' ') from dual;
LTRIM(RTRIM('
-------------
gao qian jing
11.SUBSTR(string,start,count)
取子字符串
,
从
start
开始
,
取
count
个
SQL> select substr('13088888888',3,8) from dual;
SUBSTR('
--------
08888888
12.REPLACE('string','s1','s2')
string
希望被替换的字符或变量
s1
被替换的字符串
s2
要替换的字符串
SQL> select replace('he love you','he','i') from dual;
REPLACE('H
----------
i love you
13.SOUNDEX
返回一个与给定的字符串读音相同的字符串
SQL> create table table1(xm varchar(8));
SQL> insert into table1 values('weather');
SQL> insert into table1 values('wether');
SQL> insert into table1 values('gao');
SQL> select xm from table1 where soundex(xm)=soundex('weather');
XM
--------
weather
wether
14.TRIM('s' from 'string')
LEADING
剪掉前面的字符
TRAILING
剪掉后面的字符
如果不指定
,
默认为空格符
15.ABS
返回指定值的绝对值