歸納一下平時使用過的oracle函式

2021-09-29 09:31:11 字數 2162 閱讀 6478

學習使用oracle也有一年多了,之前使用過的一些函式,鄙人現在將其做一些歸納,如果忘記了可以隨時檢視。

一、字元函式:

(1)、length(str) 返回表示式中的字元數 ;

select length(

'hello world!'

)from dual;

--返回結果:12

select instr(

'hello world!'

,'l'

)from dual;

--返回第一次出現的l的位置,返回結果:3;

select instr(

'hello world!'

,'l',6

)from dual;

--從第6位置開始搜尋,返回第一次出現的l的位置,返回結果:10;

select instr(

'hello world!'

,'l',1

,2)from dual;

--從1位置開始搜尋,返回第二次出現l的位置,返回結果:4;

還可以將instr(num,』.』)當做查詢條件,用於查詢某個欄位的值為小數的資料,例如:

select

*from bcaf_t where instr(bcaf016,

'.')

>0;

--可以查詢出bcaf016為小數的所有資料

(3)、lower(str)將字串轉換為小寫,upper(str)將字串轉換為大寫;

(4)、replace(str,seek_str,replace_str),將str字串中的seek_str用replace_str替換掉 ;

select

replace

('hello world!'

,'ello'

,'i'

)from dual;

--返回結果:hi world!

(5)、substr(str,start[,length])返回字串中的指定的字元,從start位置開始,擷取長度為length的字串。(start若為負數,則從str字串末尾開始計算;length可以省略,一直擷取到字串末尾);

二、數值函式:

ceil(value)返回大於等於value的最小整數,floor(value)返回小於等於value的最大整數

select ceil(

7.7)

from dual;

--返回結果:8

select floor(

7.7)

from dual;

--返回結果:7

三、轉換函式:

(1)、to_number(str,[format]) 將str轉換成數字格式

select to_number(

'777.77')+

77.777

from dual;

--返回結果:855.547

(2)、to_char(str,[fomat])將str轉換為數字格式或者日期格式,格式中加』fm』可以格式化數值:

其中0表示:如果引數(double或者float型別)存在數字就顯示數字,不存在就顯示0;

9表示:如果引數(double或者float型別)存在數字就顯示數字,不存在就顯示空格;

fm表示:將9帶來的空格刪除。

select to_char(

'777.77'

,'fm9990.000'

)from dual;

--返回結果:777.770

(3)、to_date(str,[format]) 將str字串轉換為日期格式

select to_date(

'2019-11-07'

,'yyyy-mm-dd'

)from dual;

--返回結果:07-11月-19

四、其他函式

(1)、listagg(***,***) within group( order by ***) 將一列資料轉換成一行

(2)、decode(value,if1,then1,if2,then2,if3,then3,…,else)

記錄一下使用過的框架大全

1.一款選擇框架 compile com.bilibili boxing impl 0.6.0 片段 private void selectimage 效果如下 2.picasso 好用的開源框架 compile com.squareup.picasso picasso 2.5.2 片段 picas...

歸納一下ORACLE中的資料型別

當你在資料庫中建立資料表的時候,你需要定義表中所有欄位的型別。oracle 有許多種資料型別以滿足你的需要。資料型別大約分為 character,number,date,lob,和raw 等型別。雖然 oracle8i 也允許你自定義資料型別,但是它們是最基本的資料型別。在下面的文章中你將了解到他們...

整理一下近期專案中使用過的sql技巧

最近參與專案的時候遇到一些問題,為避免遺忘,寫個部落格記錄一下。問題一 前台傳來的資料以1,2,3,4這種格式的數字的時候,在資料庫中進行模糊查詢,like concat 來查詢的時候會出現一些問題,會將查詢數字的資料都選出來。因此可以構造乙個字段,類似於,concat 1 篩選資料的時候 使用 a...