oracle常用函数

SQL> select concat('010-','88888888') || ' turn 203 ' myphone from dual;
 
MYPHONE
----------------------
010-88888888 turn 203
 
SQL> select ascii('A') A ascii('a') a ,ascii('0') zero ,ascii(' ') space from dual;
 

SQL> select ascii('A') A, ascii('a') a ,ascii('0') zero ,ascii(' ') space from dual;
 
         A          A       ZERO      SPACE
---------- ---------- ---------- ----------
        65         97         48         32
 
SQL> select initcap('smith'),lower('ABCde'),upper('ABCde') from dual;
 
INITCAP('SMITH') LOWER('ABCDE') UPPER('ABCDE')
---------------- -------------- --------------
Smith            abcde          ABCDE
 
SQL> select instr('oracle traning','ra',1,2) from dual;
 
INSTR('ORACLETRANING','RA',1,2
------------------------------
                             9
 
SQL> select instr('oracle traning','ra',1) from dual;
 
INSTR('ORACLETRANING','RA',1)
-----------------------------
                            2
 
SQL> select ascii('肖') from dual;
 
 ASCII('肖')
-----------
      53412
 
SQL> select chr(53412) xiao,chr(65) from dual;
 
XIAO CHR(65)
---- -------
肖   A
 
SQL> select lpad(rpad('xiao',10,'*'),18,'*') from dual;
 
LPAD(RPAD('XIAO',10,'*'),18,'*
------------------------------
********xiao******
 
SQL> select substr('130123456789',3,8) from dual;
 
SUBSTR('130123456789',3,8)
--------------------------
01234567
 
SQL> select replace('he love you ','he','i') from dual;
 
REPLACE('HELOVEYOU','HE','I')
-----------------------------
i love you
 
SQL> select ceil(3.14159),floor(3.57612) from dual;
 
CEIL(3.14159) FLOOR(3.57612)
------------- --------------
            4              3
 
SQL> select ln(1),ln(2),ln(2.7182818) from dual;
 
     LN(1)      LN(2) LN(2.7182818)
---------- ---------- -------------
         0 0.69314718 0.99999998953
 
SQL> select mod(10,3),mod(3,3),mod(2,3) from dual;
 
 MOD(10,3)   MOD(3,3)   MOD(2,3)
---------- ---------- ----------
         1          0          2
 
SQL> select power(2,10),power(3,2),power(1,5) from dual;
 
POWER(2,10) POWER(3,2) POWER(1,5)
----------- ---------- ----------
       1024          9          1
 
SQL> select power(2,2,3) from dual;
 
SQL>select round(55,5),round(-55.5),trunc(55,9),trunc(-55.9) from dual;
SQL> select round(55,5),round(-55.5),trunc(55,9),trunc(-55.9) from dual;
 
ROUND(55,5) ROUND(-55.5) TRUNC(55,9) TRUNC(-55.9)
----------- ------------ ----------- ------------
         55          -56          55          -55
 
SQL> select trunc(123.456,2),trunc(123.456,-2) from dual;
 
TRUNC(123.456,2) TRUNC(123.456,-2)
---------------- -----------------
          123.45               100
 
SQL> select to_char(add_months(to_date('2010-01-01','yyyy-mm-dd'),3)) from dual;
 
TO_CHAR(ADD_MONTHS(TO_DATE('20
------------------------------
01-4月 -10
 
SQL> select last_day(sysdate) from dual;
 
LAST_DAY(SYSDATE)
-----------------
2010-6-30 8:54:38
 
SQL> select months between('19-12月-1999','19-1月-1999') from dual;
 
 
SQL> select months_between('19-12月-1999','19-1月-1999') from dual;
 
 MONTHS_BETWEEN('19-12月-1999',
------------------------------
                            11
 
SQL> select next_day('28-6月-2010','星期六') from dual;
 
NEXT_DAY('28-6月-2010','星期六
------------------------------
2010-7-3
 
SQL> select convert('xep','we8hp','f7dec') from dual;
 
CONVERT('XEP','WE8HP','F7DEC')
------------------------------
xep
 
SQL> select to_multi_byte('肖') from dual; --全角
 
TO_MULTI_BYTE('肖')
-------------------

 
SQL> select to_single_byte('肖') from dual; --半角
 
TO_SINGLE_BYTE('肖')
--------------------

 
SQL> select greatest('AA','ab',AC),least('AA','ab',AC) from dual;
 
 
SQL> select greatest('AA','ab','AC'),least('AA','ab','AC') from dual;
 
GREATEST('AA','AB','AC') LEAST('AA','AB','AC')
------------------------ ---------------------
ab                       AA
 
SQL> select user from dual;
 
USER
------------------------------
XEP
 
SQL> select userenv('isdba') from dual;
 
USERENV('ISDBA')
----------------
FALSE
 
SQL> select userenv('sessionid') from dual;
 
USERENV('SESSIONID')
--------------------
                 273
 
SQL> select userenv('entryid') from dual;
 
USERENV('ENTRYID')
------------------
                 0
 
SQL> select userenv('instance') from dual;
 
USERENV('INSTANCE')
-------------------
                  1
 
SQL> select userenv('language') from dual;
 
USERENV('LANGUAGE')
----------------------------------------------------
SIMPLIFIED CHINESE_CHINA.ZHS16GBK
 
SQL> select userenv('lang') from dual;
 
USERENV('LANG')
----------------------------------------------------
ZHS
 
SQL> select userenv('terminal') from dual;
 
USERENV('TERMINAL')
-------------------
UWAY-B2583F0701
 
SQL> select vsize(user) from dual;
 
VSIZE(USER)
-----------
          3
 
SQL> create table table3(xm varchar(8),sal number(7,2))
;
  2  ;
 
Table created
 
SQL> insert into table3 values('gao',1111.11);
 
1 row inserted
 
SQL> insert into table3 values('gao',1111.11);
 
1 row inserted
 
SQL> insert into table3 values('zhu',5555.55);
 
1 row inserted
 
SQL> commit;
 
Commit complete
 
SQL> select avg(distinct sal) from table3;
 
AVG(DISTINCTSAL)
----------------
         3333.33
 
SQL> select avg(sal) from table3;
 
  AVG(SAL)
----------
   2592.59
 
SQL> select avg(all sal) from table3;
 
AVG(ALLSAL)
-----------
    2592.59
 
SQL> select min(all sal) form dual;
 
 
SQL> select min(all sal) from table3;
 
MIN(ALLSAL)
-----------
    1111.11
   
c:/>col deptno for a10
c:/>col deptno for 99999
c:/>select 1 deptno from dual;

DEPTNO
------
     1

c:/>select lpad('what is this',5) from dual;

LPAD(
-----
what

c:/>select lpad('what is this',5,'*') from dual;

LPAD(
-----
what

c:/>select lpad('what is this',10,'*') from dual;

LPAD('WHAT
----------
what is th

c:/>select lpad('what is this',18,'*') from dual;

LPAD('WHATISTHIS',
------------------
******what is this

c:/>select lpad('what is this',-3,'*') from dual;

L
-


c:/>select lpad('what is this',0,'*') from dual;

L
-


c:/>select lpad('what is this',1,'*') from dual;

L
-
w

c:/>select rpad('what is this',1,'*') from dual;

R
-
w

c:/>select rpad('what is this',5,'*') from dual;

RPAD(
-----
what

c:/>select rpad('what is this',50,'*') from dual;

RPAD('WHATISTHIS',50,'*')
--------------------------------------------------
what is this**************************************

c:/>select rpad('what is this',8,'*') from dual;

RPAD('WH
--------
what is

c:/>select rpad('what isthis',8,'*') from dual;

RPAD('WH
--------
what ist

c:/>select trim('  what is this ') from dual;

TRIM('WHATIS
------------
what is this

c:/>select trim('w'from'  what is this w') from dual;

TRIM('W'FROM'WH
---------------
  what is this

c:/>select trim('W' from 'What is this w W') from dual;

TRIM('W'FROM'W
--------------
hat is this w

c:/>select trim(leading 'W' from 'What is this w W') from dual;

TRIM(LEADING'W'
---------------
hat is this w W

c:/>select trim(trailing 'W' from 'What is this w W') from dual;

TRIM(TRAILING'W
---------------
What is this w

c:/>select trim(both 'W' from 'What is this w W') from dual;

TRIM(BOTH'W'FR
--------------
hat is this w

SQL> select rtrim('WWhhhhhh is tHis wW','W w') from dual;

RTRIM('WWHHHHHHI
----------------
WWhhhhhh is tHis

SQL> select ltrim('WWhhhhhh is tHis wW','W w') from dual;

LTRIM('WWHHHHHHIS
-----------------
hhhhhh is tHis wW

SQL> select replace ('WWhhhhhhaT is tHis w W','W','--') from dual;

REPLACE('WWHHHHHHATISTHIS
-------------------------
----hhhhhhaT is tHis w --

SQL> select soundex('dog'),soundex('boy') from dual;

SOUN SOUN
---- ----
D200 B000

SQL> select substr('what is this ',-5,3) from dual;

SUB
---
thi

SQL> select substr('what is this ',50,3) from dual;

S
-


SQL> select translate('what is this ','','-') from dual;

T
-


SQL> select translate('what is this ',' ','-') from dual;

TRANSLATE('WH
-------------
what-is-this-

SQL> select translate('what is this ','ait','-*') from dual;

TRANSLATE('
-----------
wh- *s h*s

SQL> select instr('abcdefg','e',-3) from dual ;

INSTR('ABCDEFG','E',-3)
-----------------------
                      5

你可能感兴趣的:(oracle,sql,table,insert,byte,Terminal)