oracle使用笔记

                1、scott解锁

alter user scott identified by tiger;

alter user scott account unlock;

2、导表

@d:/oracle/table.sql;

3、查看表结构

desc table; 

4、连接数据

'hello' || 'world'

5、去重

distinct column

6、日期转换

to_char(date,'yyyy-mm-dd')

7、转义字符

like '%\_%' escape '\'

8、查询日期94年的

like '%94'

9、字符函数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某字符首次出现的位置

instr('helloworld','w') --6 若没有返回0

14、rpad,lpad 字符补位

rpad(12000,10,'*')   --12000*****

lpad(12000,10,'*')   --*****12000

15、trim 去首位字符

trim('h' from 'hellohello') --ellohello

16、replace替换

replace('hellohello','h','x') --xelloxello 

17、数字函数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两个时间相差多少个月

months_between(date1,date2)

20、add_months 给日期加月

add_months(sysdate,12)

21、next_day 下一个星期几

next_day(sysdate,1)  --下一个星期日

22、last_day 月的最后一天

last_day(sysdate)-1  本月倒数第二天

23、round 舍入时间

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 将空值转化

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     --改表/对象名    

36、constraint

id number(8) constraint tn_id_uk unique    --列约束

constraint tn_id_uk check(id > 0)    -表约束

37、级联删除和制空

on delete set null    级联制空

on delete cascade    级联删除

38、权限

grant create view to scott    --创建视图权限

39、视图

create or replace view 

with read only    --只读

40、序列

create sequence empseq
increment by 10 --每次增长10
start with 10   --从10开始增长
maxvalue 100    --提供最大值
cycle           --需要循环

nocache         --不需要缓存登录

41、索引

create index emp_id_idx on emp(id)    --为id列创建索引

42、同义词

create synonym e for emp    --同义词

43、创建用户

create user admin identified by 123    

44、权限

grant create session to admin    --授予登录权限 

grant create table to admin    --建表权限

45、表空间

alter user aojn quota 5M(unlimited) on users

46、角色

create role manager    --创建角色manager

grant create table,create view to manager    --将创建表,创建视图权限赋予角色

grant manager to admin    --将角色赋予用户

47、分配对象权限

grant select,update on scott.emp to admin    --分给admin scott用户emp表得查看更新权限  

revoke select on scott.emp from admin  --收回权限

with grant option    --admin还可以将权限分给别人

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值