Orale单值函数.doc
文本预览下载声明
单值函数(看到函数需要知道有什么功能,能根据功能选择相应函数)
lpad()函数:用于格式化代码
SQL select lpad(21,6,0) stock_code from dual;
STOCK_ 21为原始数据,6为格式化后的位数,
------ 0是填充的字符,填充在数据左边
000021
SQL select lpad(1234567,6,0) stock_code from dual;
STOCK_
------
123456
rpad()函数:从数据右端补齐字符串
SQL select rpad(abc, 10, *) from dual;
RPAD(ABC
----------
abc*******
SQL select rpad(abcdefg, 6, *) from dual;
RPAD(
------
abcdef
lower()函数:返回小写字符串
SQL select sid,sname from tab_student where lower(sname)=lower(tom);
SID SNAME
---------- --------------------
1 Tom
upper()函数:返回大写字符串
SQL select sid,sname from tab_student where upper(sname)=upper(TOM);
SID SNAME
---------- --------------------
1 Tom
initcap ()函数:单词首字母大写
SQL select initcap(big) from dual;
INI
---
Big
SQL select initcap(bigbigtiger) from dual;
INITCAP(BI
-----------
Bigbigtiger
SQL select initcap(big_big_tiger) from dual;
INITCAP(BIG_
-------------
Big_Big_Tiger
SQL select initcap(big/big/tiger) from dual;
INITCAP(BIG/
-------------
Big/Big/Tiger
SQL select initcap(big big tiger) from dual;
INITCAP(BIGB
-------------
Big Big Tiger
length()函数:返回字符串长度
SQL select length(abcd ) from dual;
LENGTH(ABCD)
--------------
8
SQL select length() from dual;
LENGTH()
----------
SQL select length(12.51) from dual;
LENGTH(12.51)
-------------
5
substr函数():截取字符串
SQL select substr(1234567890, 5, 4) from dual;
SUBS 对1234567890截取自第五位开始的4个字符
----
5678
SQL select substr(1234567890, 5) from dual;
SUBSTR
------
567890
instr()函数:获得子字符串在父字符串中出现的位置
SQL select instr(big big tiger, big) from dual;
INSTR(BIGBIGTIGER,BIG)
--------------------------
1
SQL select instr(big big tiger, big, 2) from dual;
INSTR(BIGBIGTIGER,BIG,2)
----------------------------
5
SQL select instr(big big tiger, big, 2, 2) from dual;
INSTR(BIGBIGTIGER,BIG,2,2)
------------------------------
0
ltrim()函数:删除字符串首部空格
SQL select ltrim( a
显示全部