`

Oracle笔记

阅读更多

Oracle笔记

 

 

 

 

 

 

 

 

 

 

主编:够潮

版本:V.20110325

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

创建表空间:

 create tablespace gouchao[A1] 

 datafile 'f:\xyc01.dbf[A2] ' size 50m;

用户:

创建用户:

 

create user xuyongchao3[A3]  identified by xyc[A4] 

   default tablespace gouchao[A5] 

   temporary tablespace temp[A6] ;

 

 

修改用户密码:

alter user xuyongchao  identified by gouchao[A7] ;

设置密码过期:

 alter user gouchao password expire;

锁定用户:

alter user xuyongchao account lock[A8] ;

为用户解锁:

alter user xuyongchao account unlock[A9] ;

为用户授权:(系统权限)

grant connect[A10]  ,resource ,create table ,create session ,create procedure to xuyongchao[A11] ;

为用户授数据对象权限:

grant select[A12]  on scott.emp[A13]  to gouchao;

 

为用户撤销权限:

revoke connect[A14]  from gouchao;

创建角色:

create role student[A15] ;

为角色授权:

grant select any table ,connect[A16]  ,resource to student with admin option;

为用户授角色:

grant student[A17]  to xuyongchao;

为用户撤销角色

revoke teacher[A18]  from xuyongchao;

删除角色:

drop role teacher;

在数据字典中查询用户信息,授权情况。角色信息

查询用户信息:

select * from dba_users;

 

 select * from dba_users where username='XUYONGCHAO';

授权情况:

conn xuyongchao/xyc

select * from user_sys_privs[A19] ;

角色信息:

conn xuyongchao/xyc

select * from user_role_privs[A20] ;

 

序列

查看当前用户所创建的序列:

select * from user_sequences;

创建序列:

 create sequence S_userno[A21] 

  start with 50[A22]  increment by 10[A23] 

  MAXvalue 99[A24]  cache 10[A25] ;

修改序列

 alter sequence S_userno

   maxvalue 200 cache 20 ;

删除序列:

drop sequence  S_userno

使用序列:

nextVal[A26] :用于返回下一个序列号

Curral:用于返回当前序列号

 

insert into user(userno ,username) values(S_userno.Nextval[A27] ,'33');

同义词:

同义词是方案对象的别名,作用:1)简化对象访问2)提高对象访问的安全性

建立公共同义词:

create  public synonym public_emp[A28]  for scott.emp[A29] ;

使用同义词

select * from public_emp;

建立私有同义词:

create synonym private_emp for scott.emp;

删除公共同义词:

drop public  synonym public_emp;

删除私有同义词

drop synonym private_emp;

表:

建表:

create table user_list

    (

     user_name varchar2(23),

      user_age int

);

查看表结构:

desc user_list;

添加字段:

alter table user_list

    add (userno int );

修改字段:

alter table user_list

   modify ( user_name varchar2(50));

删除字段:

alter table user_list

drop column user_age;

对表添加数据:

insert into user_list(user_name ,userno) values('gouchao' ,10001);

insert into user_list values('xuyongchao',10003);

insert into user_list values('gouchao' ,S_userno.Nextval[A30] );

对表修改数据

update user_list

    set user_name[A31]  ='gouli' where user_name ='gouchao';

对表删除数据:

delete from user_list where userno = 10001;

删除表格:

drop table user_list;

查询:

查询所有记录:

select *[A32]  from user_list;

select userno[A33]  from user_list;

select userno ID [A34] from user_list;

select user_list[A35] .userno from user_list;

select a.userno from user_list a[A36]  ;

查询所有记录的某些字段:

select empno ,ename from emp;

查询某些字段的不同记录:

select distinct[A37]  job from emp;

单条件 的查询:

=

select  * from emp where job='CLERK';

!=

select  * from emp where job!='CLERK';

>

select * from emp where sal > 1600;

< 

select * from emp where sal < 1600;

>= 


select * from emp where sal >=1600;

<=

select * from emp where sal <= 1600;

in

select * from emp where sal in (1600,3000);

not in

select * from emp where sal not in(1600,3000);

between and

select * from emp where sal between 1600 and 3000 ;

Like

select * from emp where job like 'M%';

select * from emp where job like 'M_';

select * from  emp where job like 'MANAGE_';

not like

elect * from emp where job not like 'M_';

select * from emp where job not like 'M%';

Is null

select * from emp where sal is null;

select * from emp where job is null;

Is not null

select * from emp where sal is not null;

select * from emp where job is not null;

组合条件的查询:

and

select * from emp where job ='CLERK' and sal <3000;

or

 

0
6
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics