oracle基础知识五

来源:互联网 发布:免费程序化交易软件 编辑:程序博客网 时间:2024/04/30 22:14

分页查询
 rownum

分支语句
 case
  when .... then
  else...
 end


DML
 inert
 update
 delete

alter
 add
 modify
 drop

 constraint
  add
  modify
  drop
 

------------------------------
all

select first_name,salary
 from s_emp
 where salary >= all(1400,2000,'abc');

select first_name,salary
 from s_emp
 where salary >= 1400 and salary >=2000;


any

select first_name,salary
 from s_emp
 where salary >= any(1400,2000); 

select first_name,salary
 from s_emp
 where salary >= 1400 or salary >=1500; 

注:如果在all,any关键字后接子查询,子查询的结果集必须是单列的


---------------------union---------union all-----------
union 表示合并结果集,要求合并的结果集必须是同构的

select first_name,salary,dept_id from s_emp where dept_id = 41 or dept_id = 42
union
select first_name,salary,dept_id from s_emp where dept_id = 42;

 

select first_name,salary,dept_id from s_emp where dept_id = 41 or dept_id = 42
union all
select first_name,salary,dept_id from s_emp where dept_id = 42;

union 合并结果集,如果有重复数据,则自动排重(distinct)
union all  绝对意义上的合并结果集,如果有重复 ,数据则重复出现

 


user_constraints;
select constraint_name
 from user_constraints
 where table_name = 'H_ST';

alter table h_st
 add constraint hstpk primary key(id);

alter table h_st drop constraint hstpk;

使约束失效:
alter table h_st
 disable constraint hstpk;

恢复约束效果:要求 表中已有数据  必须遵循此约束,否则 恢复不成功

alter table h_st
 enable constraint hstpk;

删除表:
 drop table h_st;

子表中  对主表有外键引用的 那些记录给删除掉

修改表名:
 rename h_st to h_stu;

create table h_st(
 id number primary key,
 name varchar2(20)
)

 

数据查询语言:DQL
 select
数据操作语言:DML----  必须手动提交事务,操作在事务的环境中
 insert  update delete
数据定义语言:DDL----  是自动提交事务
 create TRUNCATE
数据控制语言:DCL
 commit  rollback  savepoin 

 grant----DBA

TRUNCATE--移除(截断)表中的所有数据,是不可恢复操作
-------------------------------------------
sequence     主键生成策略之一
创建序列语法:
CREATE SEQUENCE name
 [INCREMENT BY n] ----增长步长
 [START WITH n]  ----起始值
 [{MAXVALUE n | NOMAXVALUE}] ---最大值
 [{MINVALUE n | NOMINVALUE}] ---最小

create sequence h_seq;


seq.nextval---查询下一个序列值,每一次调用,序列值 都会自增1

seq.currva----查询当前序列值


user_sequences---用户字典表,用于查询  用户所创建的 序列


insert into h_stu
 values(h_seq.nextval,'abcde');

修改序列:    当序列已被初始化,则不能对起始值进行修改
alter sequence h_seq
 INCREMENT BY 2;
 
删除序列:DROP SEQUENCE seqName;


视图:
 是以个虚拟的表,是以个查询语句结果的快照


CREATE [OR REPLACE] [FORCE|NOFORCE] VIEW view
  [(alias[, alias]...)]
AS subquery


create or replace  view h_emp_view
as
 select * from s_emp where dept_id = 43;

作用:
 有利于管理员 更细粒度的控制表权限。
 有利于简化查询操作

视图:
 简单视图:建立的子查询  查询一张表 DML
  
 复杂视图:通过多表查询,建立的视图

 

原创粉丝点击