程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Oracle數據庫 >> Oracle教程 >> 單行函數

單行函數

編輯:Oracle教程

SQL> select upper('abcde') from dual;

UPPER                                                                          
-----                                                                          
ABCDE                                                                          

SQL> select lower('ABCDE') from dual;

LOWER                                                                          
-----                                                                          
abcde                                                                          

SQL> select inicap(ename) from emp;
select inicap(ename) from emp
       *
第 1 行出現錯誤:
ORA-00904: "INICAP": 標識符無效


SQL> select initcap(ename) from emp;

INITCAP(EN                                                                     
----------                                                                     
Smith                                                                          
Allen                                                                          
Ward                                                                           
Jones                                                                          
Martin                                                                         
Blake                                                                          
Clark                                                                          
Scott                                                                          
King                                                                           
Turner                                                                         
Adams                                                                          

INITCAP(EN                                                                     
----------                                                                     
James                                                                          
Ford                                                                           
Miller                                                                         
易發寶                                                                         
Hr                                                                             

已選擇16行。

SQL> select concat('a','b') from dual;

CO                                                                             
--                                                                             
ab                                                                             

SQL> select 'a'||'b' from dual;

'A                                                                             
--                                                                             
ab                                                                             

SQL> select substr('abcde',length('abcde')-2) from dual;

SUB                                                                            
---                                                                            
cde                                                                            

SQL> select substr('abcde',-3,3) from dual;

SUB                                                                            
---                                                                            
cde                                                                            

SQL> select substr('abcde',1,3) from dual;

SUB                                                                            
---                                                                            
abc                                                                            

SQL> select substr('abcde',-1,3) from dual;

S                                                                              
-                                                                              
e                                                                              

SQL> select substr('abcde',-4,3) from dual;

SUB                                                                            
---                                                                            
bcd                                                                            

SQL> select length(ename) from emp;

LENGTH(ENAME)                                                                  
-------------                                                                  
            5                                                                  
            5                                                                  
            4                                                                  
            5                                                                  
            6                                                                  
            5                                                                  
            5                                                                  
            5                                                                  
            4                                                                  
            6                                                                  
            5                                                                  

LENGTH(ENAME)                                                                  
-------------                                                                  
            5                                                                  
            4                                                                  
            6                                                                  
            3                                                                  
            2                                                                  

已選擇16行。

SQL> select replace(ename,'a','A') from emp;

REPLACE(EN                                                                     
----------                                                                     
SMITH                                                                          
ALLEN                                                                          
WARD                                                                           
JONES                                                                          
MARTIN                                                                         
BLAKE                                                                          
CLARK                                                                          
SCOTT                                                                          
KING                                                                           
TURNER                                                                         
ADAMS                                                                          

REPLACE(EN                                                                     
----------                                                                     
JAMES                                                                          
FORD                                                                           
MILLER                                                                         
易發寶                                                                         
HR                                                                             

已選擇16行。

SQL> select replace('易法寶','法','發') from dual;

REPLAC                                                                         
------                                                                         
易發寶                                                                         

SQL> select instr('hello world','or') from dual;

INSTR('HELLOWORLD','OR')                                                       
------------------------                                                       
                       8                                                       

SQL> select lpad('smith',20,'*') from dual;

LPAD('SMITH',20,'*')                                                           
--------------------                                                           
***************smith                                                           

SQL> select rpad('smith',20,'*') from dual;

RPAD('SMITH',20,'*')                                                           
--------------------                                                           
smith***************                                                           

SQL> select trim('       mr   smith     ') from dual;

TRIM('MRSM                                                                     
----------                                                                     
mr   smith                                                                     

SQL> spool off

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved