系統函數

數值函數

求絕對值
Select abs(-1) from dual
進一法
select ceil(12.1) from dual
去尾法
select floor(12.6) from dual
四捨五入
select round(12.4) from dual
四捨五入保留2..n位小數
select round(12.4123,2) from dual

數字截取
默認截取整數
select trunc(123.12) from dual
截取小數後幾位
select trunc(123.12,1) from dual
截取小數前幾位
select trunc(123.12,-1)from dual

字符函數



轉換成大寫
select upper('s') from dual

轉換成小寫
select lower('S') from dual
去掉空格(有時間空格的問題很坑)
select trim(' as ') from dual

去掉左邊空格
select ltrim(' as') from dual
select rtrim('as ') from dual
去掉左邊指定的字符
select ltrim('abcdec','ab') from dual
去掉右邊指定的字符
select rtrim('abcdec','c') from dual


替換函數
select replace('as','s','q') from dual
字符串相加
select 'aa'||'bb' from dual
select concat('aa','bb') from dual
截取字符串的函數
select substr('abcde',1,3)
from dual
求長度的函數
select length('as') from dual


轉換函數

轉化成數字
select to_number('123') from dual
轉化成字符串
select to_char(123) from dual
*轉化成字符串,格式化時間
select to_date(sysdate) from dual

來個完整年月日時分秒的時間
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual

時間24小時制
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual


處理Null的函數

*爲空返回制定的代替,不爲空返回自己
select nvl('','b') from dual

*不爲空返回參數2爲空返回參數3
select nvl2('','b','c') from dual

Oracle 自定義函數
函數必須要有一個返回值

Oracle 存儲過程
優點:
1、 存儲過程預編譯SQL語句,編譯一次後面執行不需要再編譯
執行效率快一點
2、可以再存儲過程進行SQL編碼,可以減小服務器壓力
缺點:
1、代碼量多,難以維護

 打開緩存
Set Serveroutput on

 創建存儲過程
Create procedure 存儲名
As
Begin
Dbms_output.put_line();-–輸出
End;

 執行存儲過程
Beign
存儲過程名;
End;





declare pr int;
begin
proc_ddd(1,2,pr);
Dbms_output.put_line(pr);
end;

發佈了32 篇原創文章 · 獲贊 5 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章