oracle 命令分析

命令行分析

1.修改scott用户解锁,scott默认密码为tiger

    alter user scott account unlock;      

2.escape \的转义
    select * from emp where ename like '%\_%' escape '\';     

3.   
     查询当前用户拥有的角色:select * from user_role_privs;
     查询当前用户拥有的系统权限:select * from user_sys_privs;
     查询 当前用户所有表: select * from user_tables;     //user_*    
     查询DBA角色拥有的系统权限:select * from dba_role_privs t where t.GRANTEE ='DBA'
                                                     或  select * from role_role_privs t where t.ROLE='DBA';
      查询DBA角色拥有的系统权限: select * from dba_role_privs t where t.GRANTEE ='DBA';

4.建表语句
   create table emp2(
--列级约束
       id number(10),
       name varchar2(20) constraint emp2_name_nn not null,
       email varchar2(20),
       salary number(10,2) constraint emp2_salary check(salary >1800 and salary <30000),
       department_id number(10),
--表级约束
      constraint emp2_id_pk primary key(id),
      constraint emp2_email_uk unique(email),
      constraint emp2_dept_id_fk foreign key(department_id) references dept(deptno) on delete set null
)

5.约束
    1)添加或删除约束,但不能修改约束
          alter table emp2 add constaint emp2_name_uk unique(name);
          alter table emp2 drop constraint emp2_name_uk;
    2)有效化或无效化约束
         alter table emp2 disable constraint emp2_name_uk;
         alter table emp2 enable constraint emp2_name_uk;
   3)添加Not Null 约束要使用modify语句
        alter table emp2  modify(email varchar2(20) not null);   

6.显示所有约束
   select * from user_constraints

7.oracle  number类型
    Oracle中数据类型number(m,n)中m表示的是所有有效数字的位数,n表示的是小数位的位数。m的范围是1-38,即最大38位。n的范围-84~127.
保存数据范围: -1.0e-130   <= number value  <   1.0e+126 ,保存在机器内部的范围:   1   ~   22   bytes
   有效位:从左边第一个不为0的数算起的位数。
s的情况:
n   >   0     精确到小数点右边s位,并四舍五入。然后检验有效位是否   <=   m。
n   <   0    精确到小数点左边s位,并四舍五入。然后检验有效位是否   <=   m   +   |n|。
n   =   0     此时NUMBER表示整数。
123.89                      NUMBER            123.89
1234.9876                NUMBER(6)           1235
123.89                      NUMBER(6,1)       123.9
0.09999                    NUMBER(4,5)       0.09999
12345.12345            NUMBER(6,2)       Error   (有效位为5+2   >   6)
123.89                       NUMBER(4,2)       exceeds   precision   (有效位为5,   5   >   4)
12345678                     NUMBER(5,-2)     Error   (有效位为8   >   7)
12345.345                    NUMBER(5,-2)     12300
  
8.视图
    I.使用视图的好处
        1)用子表来代替视图的工作,不能做到数据的同步更新              2)控制数据的访问        3)简化查询       4)避免重复访问的相同的数据
   II.创建视图:
                 create view emp3_view                     create or replace view emp3_view                    create or replace view emp3_view
                        as                                                                    as                                                                          as
                   select * from emp3 where id=1              select * from emp3 where id=1                           select * from emp3 where id=1
                                                                                  //修改视图   create or replace                                       with read only    //只读
                 对视图可以进行基本insert、delete、update操作,但是对于组函数(avg、count、sum、max、min等)、group by语句、distinct 关键字、rownum伪列 语句不能这三项操作。
   III.对于rownum来说,只能使用 <  和  <=,不能使用 =、>、>=,这些不能返回数据
    select t1.* from (
           select rownum rn,t.* from (
                 select * from emp     //按员工工资从高到低排列员工信息
                 order by sal desc
         ) t where rownum < 6                     //得到排名前5的工资的员工,rownum为虚拟列,只能用<或<=
   ) t1 where rn >3                                                   //得到排名第四和第五的员工,这是rn为真实列,可以进行比较操作,没有限制

9.
create table sys_user(
  id varchar(50) not null primary key,
  user_name varchar(10),
  account_non_expired number(1) not null check(account_non_expired in(0,1)) default 0
)
ORA-00907: 缺失右括号
   解决: default只能在constraint的前面

10.create user test identified by root; //创建用户test
grant connect,resouce to test ; //授予connect,resource角色给test connect角色有 create session权限,该权限能过登录,连接数据库操作,resource 角色有

11.修改表的表空间
       第一种 : alter table spaceOne.tablename  move tablespace spaceTwo;   (当前的用户必须对spaceTwo、spaceOne都有操作权限才可以。) 
       第二种:create  spaceTwo.tablename as select * from  spaceOne.tablename;(当前的用户必须对spaceTwo、spaceOne都有操作权限才可以。) 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值