Oracle使用到的一些函式

2021-10-08 20:27:22 字數 2947 閱讀 6747

2.trim()函式

去除字串兩端的空格

3.length()函式

統計字串的長度

4.case when

else end as 

5.decode函式

decode(value,if1,then1,if2,then2,if3,then3,...,else)

6.substr()函式

substr(string string, int a, int b) 返回擷取的字串(從字串string的第a個位置開始,擷取b個長度)

substr(string string, int a) 返回擷取的字串(從字串string擷取從第a個位置開始的全部字串)

7.行轉列

pivot(count(client_linkman_id)

for linkman_type in( --即要轉成列的字段

'open' as authorizedperson, --此處必須為聚合函式,

'order' as commander, --in () 對要轉成列的每乙個值指定乙個列名

'fund' as capitalallocator,

'settle' as statementsconfirmer))

9.utl_match.edit_distance_similarity()函式

utl_match.edit_distance_similarity(i_business_scope,business_scope) 計算兩個字串的相似程度

10.execute immediate

對execute immediate  的解釋如下:

簡單來說 就是你乙個儲存過程當中 建立了乙個表 table_a 然後要用insert into將其他的資料插入到這個table_a當中,但是因為你在建立過程的時候 table_a還不存在,過程就會顯示有編譯錯誤,因為table_a不存在必然導致過程無法執行,所以無法編譯成功,而把insert into語句加如到 execute immediate之後 則oracle不會再去理會這個物件是否存在,因此可以成功編譯和執行

11.replace()函式

replace(string1,string2,string3) 返回用string3在替換string1中的string2後的string1字串

12.nvl()函式

nvl(string1,string2) 如果string1不為空則返回string1,否則返回string2

13.wm_concat()函式

拼接字串

wm_concat(d.detail_id)

14.to_char()函式

to_char(sysdate, 'yyyymmdd')

15.切換使用者,修改臨時表

select sid, serial#

from v$session

where sid in

(select sid

from v$lock

where id1 = (select object_id

from user_objects

where object_name = upper('tmp_acc20010_q')));

查詢到sid,殺死會話

15.用臨時表儲存一些資料資訊用於拼接查詢

with temp as(

select 'aaa' col2 from dual union

select 'bbb' col2 from dual union

select 'ccc' col2 from dual

...),

temp1 as(

select 'ddd' col3 from dual union

select 'eee' col3 from dual union

select 'fff' col3 from dual

...)

select t1.*,t2.* from temp t1,temp1 t2;

16.檢視鎖表

select sess.sid,

sess.serial#,

lo.oracle_username,

lo.os_user_name,

ao.object_name,

lo.locked_mode

from v$locked_object lo, dba_objects ao, v$session sess

where ao.object_id = lo.object_id

and lo.session_id = sess.sid;

alter system kill session '200,8506';

alter system kill session '766,23690';

17.匯出dmp:

匯出單個表:

exp cs_account/wolf@xx.***.xx.xx:1521/*** tables=client_root file=c:\123.dmp

匯出根據某個條件匯出單個表的某些資料:

exp cs_account/wolf@xx.***.xx.xx:1521/*** file=c:\123.dmp tables=client_root query=\" where flow_id='004d5ls8fdh33'\"

匯出使用者:

exp cs_account/wolf@xx.***.xx.xx:1521/*** file=123.dmp owner=(cs_account)

18.匯入dmp

imp cs_account/wolf@xx.***.xx.xx:1521/*** file=c:\123.dmp full=y ignore=y; 

19.windows小黑窗登入資料庫:

sqlplus 使用者名稱/密碼@127.0.0.1/資料庫服務名

比如:sqlplus ***/***@xx.***.xx.xx/***

經常用到的一些函式

1.對話方塊函式 showmessage 用於在程式執行過程中顯示乙個包含乙個字串資訊的對話方塊,使用者只有對這個對話方塊準確響應後才能關閉對話方塊,進行下一步工作。語法結構 showmessage const msg string showmessage hello delphi messaged...

一些oracle函式

使用case表示式直接在select語句中執行條件邏輯 select ename,sal,case when sal 2000 then underpaid when sal 4000 then overpaid else ok end as status from emp coalesce函式用實...

oracle中一些基本函式的使用

數字計算函式 1.round函式 四捨五入 描述 傳回乙個數值,該數值是按照指定的小數字元數進行四捨五入運算的結果 引數 number 欲處理之數值 decimal places 四捨五入 小數取幾位 預設為 0 select round 123.456,0 from dual 返回123 sele...