1.instr()函数(字符查找函数)
instr( string1, string2 ) 返回string1中string2第一次出现的位置
instr( string1, string2,start_position,nth_appearance) 返回string1中string2从string1的第start_position位开始出现第nth_appearance次的位置
例子:
instr(t.home_tel,'-',1,1) 返回'-'在home_tel中从第1个位置开始第1次出现的位置
instr(t.home_tel,'-',1,2) 返回'-'在home_tel中从第1个位置开始第2次出现的位置
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))
8.merge into函数
MERGE /*+ append*/
INTO CF_ACCOUNT.t_root f
USING (select * from CF_SETT1.T_CLIENT where client_id = I_CLIENT_NO or I_CLIENT_NO is null) t
on (f.CLIENT_NO = t.CLIENT_ID)
WHEN MATCHED THEN
UPDATE
set f.Open_Date = trim(t.open_date), --开户时间
f.CLOSE_DATE = trim(t.CLOSE_DATE),
f.isactive = CF_ACCOUNT.fcn_dict_chg('is_active',t.isactive,'CORE','in');
判断into后面的表和using后面的表是否满足on后面的条件,如果满足则更新,如果不满足则插入数据
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.xxx.xx.xx:1521/XXX tables=CLIENT_ROOT file=C:\123.dmp
导出根据某个条件导出单个表的某些数据:
exp CS_ACCOUNT/wolf@xx.xxx.xx.xx:1521/XXX file=C:\123.dmp tables=CLIENT_ROOT query=\" where flow_id='004D5LS8FDH33'\"
导出用户:
exp CS_ACCOUNT/wolf@xx.xxx.xx.xx:1521/XXX file=123.dmp owner=(CS_ACCOUNT)
18.导入dmp
imp CS_ACCOUNT/wolf@xx.xxx.xx.xx:1521/XXX file=C:\123.dmp full=y ignore=y;
19.windows小黑窗登录数据库:
sqlplus 用户名/密码@127.0.0.1/数据库服务名
比如:
sqlplus xxx/xxx@xx.xxx.xx.xx/XXX
本文介绍了Oracle数据库中常用的函数,包括instr()、trim()、length()、case when、decode()、substr()、行转列、merge into、UTL_MATCH.EDIT_DISTANCE_SIMILARITY()、execute immediate、replace()、nvl()、wm_concat()、to_char()、切换用户、临时表操作、查看锁表、数据导出导入以及Windows下sqlplus登录数据库的方法。
1万+

被折叠的 条评论
为什么被折叠?



