Oracle的基本學習(三)—單行函數

來源:互聯網
上載者:User

標籤:

一、字元函數

 

1.大小寫控制函數

--lower:使字母變為小寫----upper:使字母變為大寫----initcap:使字元的第一個字母變為大寫--select   lower(‘ABC‘),  upper(‘sql‘),  initcap(‘HeLlo SQL‘) from dual;

select employee_id, department_id,last_name, salary  from employees where lower(last_name)=‘king‘;

 

2.字元控制函數

concat(str1,str2)

     串連兩個字串。

substr(str,index,n)

     截取字串,從index開始(sql字串下標第一個為1),截取n個長度。

length(str)

     擷取str的長度。

instr(str1,str2)

     str2在str1首次出現的索引,如果不存在返回0。

lpad(str1,len,str2)

     設定str1長度為len,如果長度不夠在左邊用str2補齊。

rpad(str1,len,str2)

     設定str1長度為len,如果長度不夠在右邊用str2補齊。

trim(str1,from str2)

     去掉str2中的st1,僅僅是首部和尾部的。

replace(str,str1,str2)

     把str中的str1替換成str2,全部都替換。

 

select  concat(‘hello‘,‘sql‘), substr(‘hellosql‘,2,4), instr(‘HelloWorld‘,‘o‘), length(‘hello sql‘) from dual;

 

select employee_id,last_name, salary,lpad(salary,10,‘*‘)  from employees where department_id=80;

 

--trim:僅僅去掉首位複合的----replace:替換所有的--select  trim(‘A‘ from ‘AABBAACCAA‘), replace(‘AABBAACCAA‘,‘A‘,‘M‘)from dual;

 

二、數字函數

round: 四捨五入函數。

trunc: 截斷函數。

mod: 求餘函數。

--round:四捨五入--select    round(435.45,1),   round(435.45),   round(435.45,-1)from dual;

 

--trunc:截斷--select    trunc(435.45,1),   trunc(435.45),   trunc(435.45,-1)from dual;

Oracle的基本學習(三)—單行函數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.