ORACLE 字符串处理及环境变量函数
时间:2021-07-01 10:21:17
帮助过:26人阅读
1.CONCAT 连接两个字符串;
SQL> select concat(‘010-‘,‘7163738‘) from dual;
CONCAT(‘010
-----------
010-7163738
2. LENGTH 返回字符串的长度;
SQL> select length(‘12345678‘) from dual;
LENGTH(‘12345678‘)
------------------
8
3.RPAD和LPAD
RPAD 右边填充字符 LPAD 左边填充字符
SQL> select lpad(‘James‘,10,‘-‘) as name from dual;
NAME
----------
-----James
4. LTRIM和RTRIM
LTRIM 删除左边出现的字符串 RTRIM 删除右边出现的字符串
SQL> select ltrim(rtrim(‘ JAMES ‘,‘ ‘),‘ ‘) from dual;
LTRIM
-----
JAMES
TRIM 删除两端的字符,不指定则默认为空格;
SQL> SELECT trim(‘ g ‘) from dual;
T
-
g
SQL> select trim(‘o‘ from ‘onohhooho‘) from dual;
TRIM(‘O
-------
nohhooh
5.SUBSTR(string,start,count)
取子字符串,从start开始,取count个
SQL> select substr(‘13088888888‘,3,8) from dual;
SUBSTR(‘
--------
08888888
6.REPLACE(‘string‘,‘s1‘,‘s2‘)
string 希望被替换的字符或变量
s1 被替换的字符串
s2 要替换的字符串
SQL> select replace(‘he love you‘,‘he‘,‘i‘) from dual;
REPLACE(‘HELOVEYOU‘,‘HE‘,‘I‘)
------------------------------
i love you
7. CHARTOROWID
将字符数据类型转换为ROWID类型
SQL> select rowid,rowidtochar(rowid),ename from scott.emp;
ROWID ROWIDTOCHAR(ROWID) ENAME
------------------ ------------------ ----------
AAAAfKAACAAAAEqAAA AAAAfKAACAAAAEqAAA SMITH
AAAAfKAACAAAAEqAAB AAAAfKAACAAAAEqAAB ALLEN
AAAAfKAACAAAAEqAAC AAAAfKAACAAAAEqAAC WARD
AAAAfKAACAAAAEqAAD AAAAfKAACAAAAEqAAD JONES
8.CONVERT(c,dset,sset)
将源字符串 从一个语言字符集转换到另一个字符集
SQL> select convert(‘strutz‘,‘we8hp‘,‘f7dec‘) "conversion" from dual;
conver
------
strutz
9.HEXTORAW and RAWTOHEXT
将一个十六进制构成的字符串转换为二进制
RAWTOHEXT
将一个二进制构成的字符串转换为十六进制
10.TO_CHAR(date,‘format‘) 转换成字符
SQL> select to_char(sysdate,‘yyyy/mm/dd hh24:mi:ss‘) from dual;
TO_CHAR(SYSDATE,‘YY
-------------------
2017/11/06 21:14:41
11.TO_DATE(string,‘format‘)
将字符串转化为ORACLE中的一个日期
12 .TO_NUMBER 将字符转换为数字
SQL> select to_number(‘2017‘) year from dual;
YEAR
---------
2017
13.TO_MULTI_BYTE
将字符串中的单字节字符转化为多字节字符, 就是半角转换为全角
SQL> select to_multi_byte(‘zhang‘) from dual;
TO_MULTI_B
----------
zhang
14. GREATEST and LEAST
greatest 返回最大值, 即比较字符的编码大小.
SQL> select greatest(‘AA‘,‘AB‘,‘AC‘) from dual;
GR
--
AC
least 返回最小值
二. 环境变量函数
1.UID
返回标识当前用户的唯一整数
SQL> show user
USER 为"HS_USER"
SQL> select uid from dual;
UID
----------
515
2 .USEREVN
返回当前用户环境的信息
ENTRYID,SID,TERMINAL,ISDBA,LABLE,LANGUAGE,CLIENT_INFO,LANG,VSIZE
返回当前会话ID
SQL>select userenv(‘sid‘) from dual;
USERENV(‘SESSIONID‘)
--------------------
152
LANGUAGE 返回当前语言环境
SQL> select userenv(‘language‘) from dual;
USERENV(‘LANGUAGE‘)
----------------------------------------------------
SIMPLIFIED CHINESE_CHINA.ZHS16GBK
LANG
TERMINAL 返回用户的终端或机器的标志
SQL> select userenv(‘terminal‘) from dual;
USERENV(‘TERMINA
----------------
OP_XJ
ORACLE 字符串处理及环境变量函数
标签:rtrim( from chinese 数据类型转换 bsp gre least 开始 数据