Oracle总结

创建表空间

create tablespace l_l
datafile 'D:luo.DBF'
size 5m
autoextend on next 4m
maxsize unlimited ;

创建用户默认表空间

create user luo identified by 123456 default tablespace l_l ;

修改用户默认空间

alter user luo default tablespace ts_hp;

修改密码

alter user luo identified by 123;

删除用户

drop user luo [cascade];

授会话权

(create session,create table,create index,create view,create sequence,create trriger)各种权限

grant create session to luo;

分配角色(dba,connect,resource)

grant resource to luo;

回收权限

revoke create session from luo;

回收权限

revoke resource from luo;

切换用户名

conn system/123456;

创建表

create table users(id number);

添加数据

insert into users values(1);

查询

select*from users;

删除表

drop table users;

创建表

create table students(
        id number,
        name varchar2(10),
        sex char(2),
        birthday date,
        score number(3,1),
        resume clob);

添加

alter table students add(class_id number);

修改

alter table students modify(name varchar(30));

删除

alter table student drop column score;
alter table students drop(score);
alter table students drop(score,id);

修改表名

rename students to stu;

修改列名

alter table stu rename column resume to intro;

查看表结构

desc stu;

添加数据

insert into stu values();

约束

create table class(id number primary key);
create table stu1 ( id number references class(id),
                    name varchar2(10) not null,
                    age number unique,
                    add varchar2(20)check(add in('洛阳','焦作')));

增加 not null

alter table stu modify name not null;

添加或修改

alter table stu add constraint pk_stu primary key (id);

删除约束

alter table stu drop constraint 约束名称
alter table stu drop constraint primary key cascade;

约束命名规范

NN_表名_列名:非空
UN_表名_列名:唯一
FK_表名_列名:外键
CK_表名_列名:条件
PK_表名:主键

显示约束信息

select constraint_name,constraint_type,status,validated
from user_constraints
where table_name = 'class';

update

语法:update 表名 set 列名 = 表达式[,列名=表达式,…][where 条件];

  update stu set S_name = "qq" where S_id = 1002;
  --注意:没有where条件。将修改所有行
  update stu set f_ship = 10 where f_ship is null;

delete

语法:delete from 表名 [where 条件表达式];
delete from stu where S_id = 1002;–删除一行
–注意:没有where条件,删除所有记录;
delete from 表名;删除数据,还有结构
delete table 表名;删除结构和数据
trancate table 表名;无法找回

设置保存点

savepoint 保存点名称
回滚
rollback to 保存点名称
配合delete使用的,找回delete删除的数据,而trancate无法找回

查询

select*from stu;–查询所有
select S_name,S_id from stu;–查询特定的列

select distinct S_name from stu ;– 删除重复数据
select S_name,S_id from stu where S_n = “qq”;–查询特定条件列

使用算术表达式

用null计算所有都为空,用nvl(字段,0),nvl函数用于处理null问题
用as如果加引号必须加”“可以只用as不加引号,as不能给表起别名

如何连接字符串(||)

在查询的时候希望把多列连接成一列返回就用||

to_date
to_char
and
between and

如何使用like操作符

%:任意0个或多个字符
_:表示任意单个字符

order by 排序字句

asc :升序,默认。
desc :降序

可以使用列的别名排序

分组查询

用到的函数max、min、avg、sum、count。

group by和having

group by:用于对查询的结果分组
having:用于对查询结果的限制

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值