Oracle SQL 內建函數大全(1)

來源:互聯網
上載者:User

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 .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('HELOVEYOU','HE','I')
------------------------------
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 返回指定值的絕對值
SQL> select abs(100),abs(-100) from dual;

ABS(100) ABS(-100)
--------- ---------
100       100

16.ACOS 給出反餘弦的值
SQL> select acos(-1) from dual;

ACOS(-1)
---------
3.1415927

17.ASIN 給出反正弦的值
SQL> select asin(0.5) from dual;

ASIN(0.5)
---------
.52359878

18.ATAN 返回一個數位反正切值
SQL> select atan(1) from dual;

ATAN(1)
---------
.78539816

19.CEIL 返回大於或等於給出數位最小整數
SQL> select ceil(3.1415927) from dual;

CEIL(3.1415927)
---------------
4

20.COS 返回一個給定數位餘弦
SQL> select cos(-3.1415927) from dual;

COS(-3.1415927)
---------------
-1

21.COSH 返回一個數字反餘弦值
SQL> select cosh(20) from dual;

COSH(20)
---------
242582598

22.EXP 返回一個數字e的n次方根
SQL> select exp(2),exp(1) from dual;

EXP(2)    EXP(1)
--------- ---------
7.3890561 2.7182818

23.FLOOR 對給定的數字取整數
SQL> select floor(2345.67) from dual;

FLOOR(2345.67)
--------------
2345

24.LN 返回一個數位對數值
SQL> select ln(1),ln(2),ln(2.7182818) from dual;

LN(1)     LN(2) LN(2.7182818)
--------- --------- -------------
0 .69314718     .99999999

25.LOG(n1,n2) 返回一個以n1為底n2的對數
SQL> select log(2,1),log(2,4) from dual;

LOG(2,1)  LOG(2,4)
--------- ---------
0         2


相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.