常用oracle 函式

2021-07-30 12:22:50 字數 1814 閱讀 5466

1.oracle的

substr函式的用法:

取得字串中指定起始位置和長度的字串   substr( string, start_position, [ length ] )。

例:substr('this is a test',6,2)     would 

return 'is'

substr('this is a test',6)     would 

return 'is a test'

substr('techonthenet', 

-3,3)     would 

return 'net'

2.將oracle中同一列的多行記錄拼接成乙個字串

用 wm_concat函式:

selectwm_concat(space_full_name) from zd_tobacco_storage_space where tobacco_id =' ' group by tobacco_id

需要排序時:

select ssd.tobacco_id,max(r) from

(select ssd0.space_code,ssd0.tobacco_id, wm_concat(ssd0.space_name)

over (partition by ssd0.tobacco_id order by to_number(ssd0.space_code)) r

from zd_tobacco_storage_space_detai ssd0)ssd

group by ssd.tobacco_id

3.查詢不包含漢字的( like '%\%' 是包含 ,not like 不包含)

where asciistr(t.tobacco_code) not like '%\%'

4.查詢每條資料當天最後一條

select wh.unit_id,

wh.client_id,

wh.client_name,

wh.large_address_id,

wh.large_address_name,

wh.tobacco_type,

wh.tobacco_state,

wh.tobacco_number,wh.tobacco_weight,wh.change_time,

row_number() over(partition by

wh.tobacco_id

order by

wh.change_time

desc)rn

根據wh.tobacco_idgroup by再根據wh.change_time時間倒序查,該分組rn從1開始

from view_tobaccoreceive_record wh

5.四捨五入

round(to_number(sum(b.afwei))/to_number(decode(sum(b.bfwei),0,1,sum(b.bfwei))),5)

6.類似於三目運算

decode(sum(b.bfwei),0,1,sum(b.bfwei))

當sum(b.bfwei)=0時,取值為1,當sum(b.bfwei)!=0時,取值sum(b.bfwei)

Oracle常用函式

一 row number over 資料甲 1 select column name column name,data type,2 row number over partition by column name order by column name row num 3 from test c...

Oracle常用函式

數學函式 1.絕對值 o select abs 1 value from dual 2.取整 大 o select ceil 1.001 value from dual 3.取整 小 o select floor 1.001 value from dual 4.取整 擷取 o select trun...

oracle常用函式

1.concat c1,c2均為字串,函式將c2連線到c1的後面,如果c1為null,將返回c2.如果c2為null,則返回c1,如果c1 c2都為null,則返回null。他和操作符 返回的結果相同 select concat slobo svoboda username from dualuse...