Chinaunix首页 | 论坛 | 博客
  • 博客访问: 663331
  • 博文数量: 779
  • 博客积分: 5000
  • 博客等级: 大校
  • 技术积分: 5000
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-27 13:28
文章分类

全部博文(779)

文章存档

2011年(1)

2008年(778)

我的朋友

分类:

2008-10-27 13:38:51

 /*===================================================================
 *Author: MartriWang@gmail.com
 *Date:  09/05/2007
 *Description:ORACLE Function
 *==================================================================*/
 
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 删除右边出现的字符串
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

 

[1]           ...

【责编:Peng】

--------------------next---------------------

阅读(311) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~