oracle对substr去重,oracle使用笔记
1、scott解鎖
alter user scott identified by tiger;
alter user scott account unlock;
2、導(dǎo)表
@d:/oracle/table.sql;
3、查看表結(jié)構(gòu)
desc table;
4、連接數(shù)據(jù)
'hello' || 'world'
5、去重
distinct column
6、日期轉(zhuǎn)換
to_char(date,'yyyy-mm-dd')
7、轉(zhuǎn)義字符
like '%\_%' escape '\'
8、查詢?nèi)掌?4年的
like '%94'
9、字符函數(shù)lower,upper,initcap
initcap('hello world') --Hello World
10、concat連接
concat('hello','world') ?--helloworld
11、substr截取
substr('helloworld',2,4) --ello
12、length長度
length('helloworld') --10
13、instr某字符首次出現(xiàn)的位置
instr('helloworld','w') --6 若沒有返回0
14、rpad,lpad 字符補(bǔ)位
rpad(12000,10,'*') ? --12000*****
lpad(12000,10,'*') ? --*****12000
15、trim 去首位字符
trim('h' from 'hellohello') --ellohello
16、replace替換
replace('hellohello','h','x') --xelloxello
17、數(shù)字函數(shù)round
round(155.555) -- 156
round(155.555,2) --155.56
round(155.555,-2) --200
18、mod取余
mod(1100,300) --200
19、months_between兩個(gè)時(shí)間相差多少個(gè)月
months_between(date1,date2)
20、add_months 給日期加月
add_months(sysdate,12)
21、next_day 下一個(gè)星期幾
next_day(sysdate,1) ?--下一個(gè)星期日
22、last_day 月的最后一天
last_day(sysdate)-1 ?本月倒數(shù)第二天
23、round 舍入時(shí)間
round(sysdate,'hh')
24、to_char
to_char(1234567.89,'L999,999,999,99) --¥1,234,567.89
to_char(1234567.89,'000,000,000,00) --001,234,567.89
25、to_number
to_number('¥1,234,567.89','L999,999,999,99') ?--1234567.89
to_number('001,234,567.89','000,000,000,00) --?1234567.89
26、nvl?將空值轉(zhuǎn)化
nvl(column,0)
nvl(to_char(number),'ABC')? --如果number是空,顯示ABC
27、nvl2?類似三目
nvl2(column,'A','B') --如果column不為空顯示A,為空顯示B
28、NULLIF
nullif('e1','e2') --如果e1等于e2?返回null?否則返回e1
29、coalesce
coalesce(a,b,c) --如果a為空返回b如果b為空返回c
30、case when then else end
case column when 1 then 1 else 2 end?如果列值等于1顯示1,否則顯示2
31、decode
decode(column,1,1,2,2,3)?如果列值等于1顯示1,如果等于2顯示2否則顯示3
32、truncate,delete
truncate table name? ? --清空表
delete from table? ? --清空表,可以rollback
33、add
alter table name add(email varchar2(10))? ? --添加字段
34、modify
alter table name modify(email varchar2(20) default '12345@qq.com')
35、rename
alter table name rename column email to new_email? ? --改字段名
rename stu1 to stu2 ? ? --改表/對(duì)象名
36、constraint
id number(8) constraint tn_id_uk unique? ? --列約束
constraint?tn_id_uk?check(id > 0)? ? -表約束
37、級(jí)聯(lián)刪除和制空
on delete set null? ? 級(jí)聯(lián)制空
on delete cascade? ? 級(jí)聯(lián)刪除
38、權(quán)限
grant create view to scott? ? --創(chuàng)建視圖權(quán)限
39、視圖
create or replace view
with read only? ? --只讀
40、序列
create sequence empseq
increment by 10 --每次增長10
start with 10? ?--從10開始增長
maxvalue 100? ? --提供最大值
cycle? ? ? ? ? ?--需要循環(huán)
nocache? ? ? ? ?--不需要緩存登錄
41、索引
create index emp_id_idx on emp(id)? ? --為id列創(chuàng)建索引
42、同義詞
create synonym e for emp? ? --同義詞
43、創(chuàng)建用戶
create user admin identified by 123
44、權(quán)限
grant create session to admin? ? --授予登錄權(quán)限
grant create table to admin? ? --建表權(quán)限
45、表空間
alter user aojn quota 5M(unlimited) on users
46、角色
create?role?manager? ? --創(chuàng)建角色manager
grant create table,create view to manager? ? --將創(chuàng)建表,創(chuàng)建視圖權(quán)限賦予角色
grant manager to admin? ? --將角色賦予用戶
47、分配對(duì)象權(quán)限
grant select,update on scott.emp to admin? ? --分給admin scott用戶emp表得查看更新權(quán)限
revoke select on?scott.emp from admin ?--收回權(quán)限
with?grant?option? ? --admin還可以將權(quán)限分給別人
總結(jié)
以上是生活随笔為你收集整理的oracle对substr去重,oracle使用笔记的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: oracle的asmcmd获取归档日志,
- 下一篇: oracle 操作树大全,oracle树