溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

PLSQL操作符有哪些

發(fā)布時間:2022-01-17 16:59:20 來源:億速云 閱讀:292 作者:iii 欄目:關(guān)系型數(shù)據(jù)庫

這篇“PLSQL操作符有哪些”文章的知識點(diǎn)大部分人都不太理解,所以小編給大家總結(jié)了以下內(nèi)容,內(nèi)容詳細(xì),步驟清晰,具有一定的借鑒價值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來看看這篇“PLSQL操作符有哪些”文章吧。

一、字符函數(shù)


1. LOWER (strexp) - 返回字符串,并將所有的字符小寫.

select lower('ABCDE') from dual

2. UPPER (strexp)     返回字符串,并將所有的字符大寫.

select upper('abcdf') from dual

3. INITCAP(strexp)    將字符串的(每個單詞的)第一個字母變?yōu)榇髮?后面的小寫;

select initcap(' source fore') from dual select initcap(' SOURCE FORE') from dual -- Source Fore(如果都是大寫會自動將第一個字母變?yōu)榇髮懫渌男?

4. CONCAT(strexp, strexp):  連接兩個字符串

select concat(first_name,last_name) from employees

5. SUBSTR(str,start_index,length): 從指定的位置截取指定長度的字符串

select substr('abcdefg',2,3) from dual

6. LENGTH(strexp):返回字符串的長度

select length('abcdef') from dual

7. INSTR(C1,C2,I,J): 在一個字符串中搜索指定的字符,返回發(fā)現(xiàn)指定的字符的位置;

C1:搜索的字符

C2:要搜索的字符

I:表示從哪個位置開始查找

J:查找第幾次出現(xiàn)

select instr('aborcdoryuklhorp','or',1,2) from dual ---7 select instr('aborcdoryuklhorp','or',6,2) from dual ---14

8. LPAD( string1, padded_length, [ pad_string ] )   在列的左邊粘貼字符

select lpad('acd',8) from dual

9. RPAD(粘貼字符)    RPAD? 在列的右邊粘貼字符

select rpad('acd',8,'') from dual select rpad('acdefghijklm',8,'') from dual

10. TRIM(str):截取字符串兩端特殊字符

select ' abd ' from dual select trim(' abd ') from dual

11. REPLACE(str,search_str[,replace_str]): 將每次在str中出現(xiàn)的search_str用replace_str替換

select replace('HELOVEYOU','HE','I') from dual

二、數(shù)學(xué)函數(shù)


1. ROUND:傳回一個數(shù)值,該數(shù)值是按照指定的小數(shù)位數(shù)進(jìn)行四舍五入運(yùn)算的結(jié)果。

select round(3000.926) from dual --3001 --小數(shù)部分是兩位 select round(3000.926,2) from dual --3000.93

2. TRUNC函數(shù)返回處理后的數(shù)值,其工作機(jī)制與ROUND函數(shù)極為類似,

--只是該函數(shù)不對指定小數(shù)前或后的部分做相應(yīng)舍入選擇處理,而統(tǒng)統(tǒng)截去。 select trunc(3000.926) from dual --3000 select trunc(3000.926,2) from dual --3000.92

3. MOD(number1,number2)兩個數(shù)值相除并返回其余數(shù)。運(yùn)算符執(zhí)行 number1 除以 number2 操作

select mod(1600,300) from dual --100

三、轉(zhuǎn)化函數(shù)


1. TO_CHAR(date,'fmt') : 是字符類型的函數(shù),轉(zhuǎn)化日期為字符格式('fmt')

  • 必須用單引號括起來,并且是大小寫敏感

  • 可包含任何有效的日期格式

  • fmt值的寬度正好能容納所有的有效數(shù)字

2. 修改當(dāng)前的語言環(huán)境為中文

alter session set nls_language='SIMPLIFIED CHINESE'
--輸入當(dāng)前的系統(tǒng)日期,格式為 yyyy-mm-dd select sysdate from dual select to_char(sysdate,'yyyy-mm-dd') from dual --輸入當(dāng)前的系統(tǒng)日期,格式為 yyyy-mon-dd select to_char(sysdate,'yyyy-mon-dd') from dual --輸入當(dāng)前的系統(tǒng)日期,格式為 yyyy-month-dd select to_char(sysdate,'yyyy-month-dd') from dual --輸入當(dāng)前的系統(tǒng)日期,格式為 yyyy-mon-dd-day select to_char(sysdate,'yyyy-mon-dd day') from dual --輸入當(dāng)前的系統(tǒng)日期,格式為 yyyy-mon-dd-dy select to_char(sysdate,'yyyy-mon-dd-dy') from dual --輸入當(dāng)前的系統(tǒng)日期,格式為 yyyy-mon-dd-dy-d select to_char(sysdate,'yyyy/mon/dd/dy/d') from dual --ddspth 日期的英文顯示 --輸入當(dāng)前的系統(tǒng)日期,格式為 yyyy-mon-ddspth select to_char(sysdate,'yyyy-mon-ddspth') from dual --2010-4月 -seventeenth

3. 修改為英文環(huán)境(此語句只對當(dāng)前的窗口有效,當(dāng)窗口關(guān)閉虛重新設(shè)置)

alter session set nls_language=AMERICAN; --輸入當(dāng)前的系統(tǒng)日期,格式為 yyyy-mm-dd select to_char(sysdate,'yyyy-mm-dd') from dual --輸入當(dāng)前的系統(tǒng)日期,格式為 yyyy-mon-dd select to_char(sysdate,'yyyy-mon-dd') from dual --2010-apr-17 --輸入當(dāng)前的系統(tǒng)日期,格式為 YYYY-MON-DD select to_char(sysdate,'yyyy-MON-dd') from dual --2010-APR-17 --輸入當(dāng)前的系統(tǒng)日期,格式為 YYYY-MONTH-DD select to_char(sysdate,'YYYY-MONTH-DD') from dual --輸入當(dāng)前的系統(tǒng)日期,格式為 yyyy-mon-dd-day select to_char(sysdate,'yyyy-mon-dd-day') from dual select to_char(sysdate,'yyyy-mon-dd-DAY') from dual --2010-apr-17-SATURDAY --輸入當(dāng)前的系統(tǒng)日期,格式為 yyyy-mon-dd-dy select to_char(sysdate,'yyyy-mon-dd-dy') from dual --2010-apr-17-sat select to_char(sysdate,'yyyy-mon-dd-DY') from dual --2010-apr-17-SAT

4. ddspth 不分中英文環(huán)境 日期的英文顯示

--輸入當(dāng)前的系統(tǒng)日期,格式為 yyyy-mon-ddspth select to_char(sysdate,'yyyy-mon-ddspth') from dual --2010-apr-seventeenth --小時 分 秒 --輸入當(dāng)前的系統(tǒng)日期,格式為 yyyy-mon-dd HH24:MI:SS select to_char(sysdate,'yyyy-mon-dd HH24:MI:SS') from dual --輸入當(dāng)前的系統(tǒng)日期,格式為 dd-mon-yyyy SS:HH24:MI(格式?jīng)]有順序) --注意:使用to_char函數(shù)轉(zhuǎn)化日期--->字符 格式?jīng)]有順序 select to_char(sysdate,'dd-mon-yyyy SS:HH24:MI') from dual --輸入當(dāng)前的系統(tǒng)日期,格式為 yyyy-mon-dd HH24:MI:SS AM(PM) --增加AM PM  --在這個格式中AM PM沒有區(qū)別 ,表達(dá)的含義是一致的 select to_char(sysdate,'yyyy-mon-dd HH24:MI:SS AM') from dual select to_char(sysdate,'yyyy-mon-dd HH24:MI:SS PM') from dual select to_char(sysdate,'yyyy-mon-dd HH24:MI:SS PM') from dual --輸入當(dāng)前的系統(tǒng)日期,格式為 dd of  month (19 of 1月) --可以在格式中增加字符串,字符串用""引起來 select to_char(sysdate,'dd  of  month ') from dual

5. to_date(char,fmt)  轉(zhuǎn)化字符為日期

第一個參數(shù):符合日期格式的字符
第二個參數(shù):格式(同to_char函數(shù)轉(zhuǎn)化日期的格式) alter session set nls_language='SIMPLIFIED CHINESE' alter session set nls_language=AMERICAN; --轉(zhuǎn)化2008-04月-18這個字符為日期 select to_date('2008-4月-18','yyyy-mon-dd') from dual; select to_date('4月-18-2008','mon-dd-yyyy') from dual;

6.TO_CHAR(number,'fmt'):是字符類型的函數(shù),轉(zhuǎn)化數(shù)字為字符

四、日期函數(shù)


1. 計算2008-4月-1日和2008-8月-10日相差多少個月--使用months_between(date1,date2)函數(shù)

select months_between(to_date('2008-4月-01','yyyy-mon-dd'),to_date('2008-8月-10','yyyy-mon-dd')) from dual select months_between(to_date('2008-8月-10','yyyy-mon-dd'),to_date('2008-4月-01','yyyy-mon-dd')) from dual

2. 相差多少個月四舍五入到整數(shù)

select round(months_between(to_date('2008-8月-10','yyyy-mon-dd'),to_date('2008-4月-01','yyyy-mon-dd')))from dual --給出日期2008-4月-01  計算六個月后的日期 --使用Add_months(date1,number) select add_months(to_date('2008-4月-01','yyyy-mon-dd'),6) from dual

3. 給出日期date和星期x之后計算下一個星期的日期--使用NEXT_DAY(date,'day')

select next_day(to_date('2010-4月-01','yyyy-mon-dd'),'星期三') from dual

4. 計算指定日期所在月份的最后一天的日期--使用last_day(date)

select last_day(to_date('2010-3月-01','yyyy-mon-dd')) from dual

以上就是關(guān)于“PLSQL操作符有哪些”這篇文章的內(nèi)容,相信大家都有了一定的了解,希望小編分享的內(nèi)容對大家有幫助,若想了解更多相關(guān)的知識內(nèi)容,請關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI