oracle 基础

1.order by 排序

    select * from dept order by desc; --降序

    select ename,empno from emp order by empno asc;  --对 empno升序排列

  select ename,empno from emp where deptno<>10 order by empno asc;-- deptno进行升序排列同时过滤deptno=10的数据

   select ename,sal,deptno from emp order by deptno asc,ename desc;  --deptno进行升序排列的前提下,ename进行降序排列

 

2.去重

   <1> distinct

       distinct关键字只能过滤查询字段中所有记录相同的(记录集相同),而如果要指定一个字段却没有效果,另外distinct关键字会排序,效率很低 。

           例:

      select distinct name from t1 能消除重复记录,但只能取一个字段,现在要同时取id,name这2个字段的值。

       select distinct id,name from t1 可以取多个字段,但只能消除这2个字段值全部相同的记录

   <2>group by 

        例如要显示的字段为A、B、C三个,而A字段的内容不能重复可以用下面的语句:

            select A, min(B),min(C),count(*) from [table] where [条件] group by   A  having [条件] order by A desc   -- count(*)  重复次数

           如果在上句中having加 count(*)>1   就可以查出记录A的重复次数大于1的记录

    如果在上句中having加 count(*)>2   就可以查出记录A的重复次数大于2的记录

 3. group by 字句 分组查询

     select deptno ,sum(sal) from emp group by deptno;   --统计各个部门的员工的工资的总和

 

4.在表student的SNAME属性上创建索引student_sname_idx

     create index student_sname_idx on student(sname);

5 按如下要求创建表class和student

属性

类型(长度)

默认值

约束

含义

CLASSNO数值 (2)主键班级编号
CNAME变长字符 (10)非空班级名称

属性

类型(长度)

默认值

约束

含义

STUNO数值 (8)主键学号
SNAME变长字符 (12)非空姓名
SEX字符 (2)性别
BIRTHDAY日期生日
EMAIL变长字符 (20)唯一电子邮件
SCORE数值 (5, 2)检查成绩
CLASSNO数值 (2)外键,关联到表CLASS的CLASSNO主键班级编号

答:create table class

(classno number(2) constraint class_classno_pk primary key,

cname varchar2(10) not null);

create table student

(stuno number(8) constraint student_stuno_pk primary key,

sname varchar2(12) not null,

sex char(2) default ‘男’,

birthday date,

email varchar2(20) constraint student_email_uk unique,

score number(5,2) constraint student_score_ck check(score>=0 and score<=100),

classno number(2) constraint student_classno_fk references class(classno)

);

 

6. 创建序列stuseq,要求初值为20050001,增量为1,最大值为20059999。(6分)

答:create sequence stuseq increment by 1 start with 20050001 maxvalue 20059999;

 

7.授权

 grant create,select , update,delete on  表名 to  用户名;

8.收回权限

      revoke create,select , update,delete on 表名 from 用户名

9.锁住用户

    alter user 用户名 account lock;

10.给用户解锁

alter user TEST_SELECT account unlock; 

11.创建用户

   create user 用户名     identified by  创建人名;

12 创建同义祠(不同用户)

create synonym  表名 for   用户名.表名

 

    

转载于:https://www.cnblogs.com/interfacehwx/p/5499695.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值