oracle数据库

SQL组成:

DDL:数据库模式定义语言 关键字:create drop
DML:数据库操作语言 关键字:insert update select
DCL:数据库控制语言 关键字:grant remove revoke
TCL:事物控制语言 关键字:commit rollback
运算符: = > < >= <= <> !=
通配符: _(一个字符) %(/任意长度字符)like 一起使用
逻辑表达式: and or not
连接操作符 ||

1.用户
1.1创建用户

create user yc 用户名 identified by a 密码;

1.2删除用户

drop user yc;用户名

2.表空间
SYSTEM :系统表空间
UBDOTBS1 撤销表空间 存储被修改的数据 用于数据的恢复
SYSAUX 系统辅助表空间 用于数据库组件的数据
TEMP 临时表空间
EXAMPLE :scott
2.1创建表空间的语法

create tablespace ycspace –表空间名 datafile ‘D:ycspace.dbf’–数据文件 size
10M –数据文件的初始大小 autoextend on next 200M –下一次增长200M maxsize 2048M
–最大大小为2048M

2.2删除表空间

drop tablespace ycspace; drop tablespace ycspace including contents
and datafiles; –删除表

空间的数据和内容
2.3修改表空间状态

alter tablespace ycspace1 offline/online;

2.4修改表空间只读只写

alter tablespace ycspace read only/read write;

–赋予权限

grant create session to yc; grant create table to yc; grant unlimited
tablespace to yc;–赋予yc使用表空间的权限

3.建表

create table user( id number primary key, name varchar2(10) )

—-对表的数据

–插入 insert into user values();
–修改 update user set name where id= ;
–删除 delete from user where id= ;

—-对表

–删除表 drop table user;
–复制表 create table user1 as select * from user;

—-对表的字段

alter table user add 字段名 数据类型;

–删除一个字段

alter table user drop column 字段名;

–修改数据类型

alter table user modify sex varchar2(20);

–修改字段的名字

alter table user rename column age to new-age;

–修改表名

rename user to new-user;

–增加一个约束为某个字段 检查约束

alter table user add constraints ck_user_sex check(sex in(‘男’,’女’));

–唯一约束 alter table user add constraints 约束名 unique;
–非空约束 alter table user modify 字段名 字段类型 not null;
–外键约束 alter table user add constraints 外键约束名 foreign key (列名)references 主表(列名)
–修改表 禁用一个约束

alter table user disable constraints ck_user_sex;

–删除约束

alter table user drop constraints 约束名;

函数:
数字函数:

例: select e.empno,e,ename,sysdate-e.hiredate,floor(sysdate-e.hiredate)
from emp e;

字符函数:

select distinct e.job,e.empno from emp e; select e.*,lower(e.ename)
from emp e; select e.*,length(e.ename) from emp e; select
e.*,substr(e.ename,1,3) from emp e;

字符替换:

select e.ename,replace(e.ename,’TH’,’ss’)from emp e;

转换函数

select to_char(sysdate,’yyyy-mm-dd’) from dual; select
to_date(‘2016-3-12’,’yyyy-mm-dd’)from dual;
–avg min max sum count

**——————————————
分区**

create table grade( sno number, sname varchar2(20), grade number ) partition by range(grade)( partition p1 values less than(60), partition p2 values less than(80), partition p3 values less than(maxvalue),

) select * from grade partition(p1);

–合并分区 merge

alter table grade merge partition p3,p4 into partition p34;

–拆分分区 split

alter table grade split partition p34 at(90) into (partition
p3,partition p4);

–生成编号C0001-C9999编号

create sequence seq_cid;

–创建触发器

create or replace trigger tri_cid before insert on grade for each row
begin select ‘C’||lpad(seq_cid.nextval,4,’0’) into :new.sno from
dual; end; insert into grade values (1, , )

–分页查询

select n.* from (select t.,rownum rn from (select from teacher) t
where rownum<10) n where rn>5;

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值