史上最全Oracle语法合集

您所在的位置:网站首页 史上最全的英语语法大全 史上最全Oracle语法合集

史上最全Oracle语法合集

2024-07-17 15:39| 来源: 网络整理| 查看: 265

查询

select 列名 from 表名 as [别名] where[条件表达式] like [模糊查询]

排序

selec 列名 from 表名order by asc(升序) desc(降序)

集合 并集:

select * from emp where sal>1000 union all/union(去重) select * from emp where sal(子查询) exists/not exists:如果子查询查出数据则真,查不出则条件不成立 select * from emp where eists(子查询) having 后:select * from emp gruop by empno having (子查询) select 和from 之间:select (子查询) from emp

分页SQL:

select 列名rownum from 表名 select 列名 row_number()over(order by 列名 desc) r from 表名 selecr 列名 dense_rank()over(order by 列名 desc) r from 表名 selecr 列名 rank()over(order by 列名 desc) r from 表名 selecr 列名 rank()over(partition by 列名order by 列名 desc) r from 表名 select 列名 case when from 表名

创建表空间:

create tablespace 表空间名 datafile 路径 size 1G autoextend 空间大小自动扩展 on nex 100M表空间满了以后扩展的大小 maxsize 表空间最大存储值 unlimited 不限制表空间最大值

修改表空间:

alter database datadile 路径 autoextend on next 200M maxsize 2G

修改原有数据文件大小:

alter database datafile 路径 resize 100M 为表空间增加新的数据文件 alter tablespace 表空间名 add datafile 数据文件size 大小

临时表空间

create temporary tablespace 表空间名 tempfile 路径 size 1G autoextend on next 100M maxsize unlimited

创建用户:

create user 用户名 default tablespace用户存在的表空间 temporary tablespace 临时表空间名 identified by 指定用户密码password 用户密码

修改用户:

alter user 用户名 default tablespace用户存在的表空间 temporary tablespace 临时表空间名 identified by 指定用户密码password 用户密码

系统权限:

grant create session to est1允许用户连接到数据库上 grant create table to test1允许用户创建表 grant unlimited tablespace to test1允许test1用户任意使用表空间

对象权限:

grant select on 用户名.表名 to test1 允许用户查询表的记录 grant update on 用户名.表名 to test1 允许用户更新表的记录 grant all on 用户名.表名 to test1 允许用户插入、删除、更新、查询表的记录

删除用户:

drop user 用户名 删除表空间: drop tablespase 表空间名 删除表空间的同时删除数据文件: drop tablespase 表空间的名字 including contents and datafiles

创建表:

create table 表名(字段名 数据类型 约束 默认值(可省略) 字段名 数据类型 约束 默认值, 字段名 数据类型 约束 默认值 表级约束--可选 ) tablespace 表空间名

删除表:

drop table 表名 备份表: create table 表名 as select * from 表名

约束:

not null 非空约束 unique 唯一约束 primary key主键约束 foreign key 外键约束 check 检查约束

给表添加列

alter table 表名 add 列名 数据类型 [约束] [默认值]

删除表中的一个列

alter table 表名 drop column 列名

修改一个列

alter table 表名 modify 被修改列名 数据类型 [约束][默认值] --注:请看《Oracle——数据类型、建表、约束、修改表和约束、表的注释》 增加一个约束: alter table 表名 add 表级约束法 alter table 表名 add constraint 约束名 unique(列名) alter table 表名 add constraint 约束名 primary key(列名) alter table 表名 add constraint 约束名 foreign key(外键列) references 主表名(主表主键列) alter table 表名 add constant 约束名 check(约束条件)

删除一个约束:

alter table 表名 drop constraint 约束名 给表加注释: comment on table 表名 is ‘注释’; comment on table user_info is ‘用户基础信息表’; comment on column 表名.列名 is ‘注释’; comment on column user_info.id is ‘主键’;

插入语句:

insert into 表名(列1,列2,列3) values(字段值1,字段值2,字段值3 ) --从已有数据库表中某一条数据插入到另一个表 insert into 表名(列名1,列名2,列名3)select子查询(可用集合并集等)

修改语句:

update 表名 set 列名=值,列名=值 where条件

删除语句:

delete from 表where 条件——删除表数据,保留表结构,根据条件删除 truncate table 表名——删除表中所有数据保留结构,不记录日志 drop table 表名——删除表结构和数据

创建索引:

create index 索引名 on 表名(索引列名1[,索引列名2]) 注:用索引为条件查询是,不要再索引上进行数学运算

删除索引:

drop index 索引名

创建视图:

create [or replace如果视图存在则替换][force基表不存在也可创建视图] view 视图名 [with check option] 子句保证能在视图条件内对视图进行DML [with read only] 表示是一个只读视图

删除视图

drop view 视图名

创建序列:

create sequence 序列名 start with A指定序列的初始值,A为自然数 increment by B指定序列每次增加多少,B为自然数 minvalue C指定序列的最小值,C为自然数 maxvalue D指定序列最大值,D为自然数 cache/no cache 指序列缓存,默认20个 cycle/no cycle 指定序列是否循环生成

修改序列:

alter sequence 序列名 maxvalue 2000 cycle

删除序列:

drop sequence 序列名

创建同义词:

create [public公共的] [or replace] synonym 同义词名 for 同义词对象(表名、视图名等)

删除同义词

drop synonym 表名 drop public synonym 表名


【本文地址】


今日新闻


推荐新闻


    CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3