码迷,mamicode.com
首页 > 数据库 > 详细

oracle基础

时间:2018-07-04 20:37:55      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:grant   rar   admin   commit   --   运行   匹配   事务控制   一个用户   

一、Oracle安装

1.windows10安装oracle

  将Oracle的两个压缩包解压到同一个文件夹下,点击setup.exe进行安装,如果安装过程中出现系统环境不匹配的情况,则找到文件cvu_prereq.xml,在D:\oracle_software\database\stage\cvu路径下,添加以下内容:

1 <OPERATING_SYSTEM RELEASE="6.2">
2     <VERSION VALUE="3"/>
3     <ARCHITECTURE VALUE="64-bit"/>
4     <NAME VALUE="Windows 10"/>
5     <ENV_VAR_LIST>
6     <ENV_VAR NAME="PATH" MAX_LENGTH="1023" />
7     </ENV_VAR_LIST>
8 </OPERATING_SYSTEM>

  正常安装后可以用oracle自带的sqlplus进行测试是否安装成功。

  常见的Oracle命令:alter user [user] account unlock;    alter user [user] identified by [pwd]------------解锁用户并给该用户设置密码。

2.oracle的常见术语

  数据文件对应物理上的结构,表空间对应逻辑上的结构,日志文件记录着数据库的操作。

  控制文件是二进制文件,维护着数据库的全局物理结构,支持数据库的启动和运行,数据在使用过程中不断的更新着控制文件。

二、Oracle与Sql

1.DCL(数据控制语言)

  事务控制:rollback,commit和savepoint

  权限控制:grant和revoke

  新建用户后,一般都会赋予connect和resource权限,才能进行连接操作。

grant connect,resource to user;

2.DDL(数据定义语言)

  create语句:可以创建数据库和数据库的一些对象。
  drop语句:可以删除数据表、索引、触发程序、条件约束以及数据表的权限等。
  alter语句:修改数据表定义及属性。

oracle 创建一个用户并指定默认表空间和临时表空间

1.创建临时表空间
create temporary tablespace temptest
tempfile ‘d:/dbtest/temptest.dbf‘ size 50m autoextend on next 100m
maxsize 1024m extent management local;
2.创建数据表空间
SQL> create tablespace datatest
  2  datafile ‘d:/dbtest/datatest.dbf‘
  3  size 100m
  4  autoextend on next 100m
  5  maxsize 1024m
  6  extent management local autoallocate
  7  segment space management auto;
3.创建用户,给用户指定默认表空间和临时表空间
SQL> create user test identified by test
  2  default tablespace datatest
  3  temporary tablespace temptest;
4.给用户授权
grant connect,resource to test;
5.收回赋予用户的权限
revoke connect,resource from test;

权限传递,用户test1,test2,赋予test1权限,那么test1就可以将得到的权限赋予给test2

create user test1 identified by test1; create user test2 identified by test2; connect / as sysdba; grant connect,resource to test1 with admin option;

connect test1/test1;
grant connect,resource to test2;

删除用户并且连用户的表空间一起删除

SQL> drop user test cascade;
 
User dropped

 

3.DML(数据操纵语言)

  1.insert语句     

1 --复制表
2 create table student_copy as select * from student;
3 --修改表中的数据
4 update student_copy set sno=3 where sno=1;
5 update student_copy set sno=4 where sno=2;
6 --整个记录的每一列都插入
7 insert into student select * from student_copy where sno=3;
8 --插入记录的指定列
9 insert into student (sno,sname) select sno,sname from student_copy where sno=4;

   2.update语句:

1 --更新指定列
2 update student set sname=xiaoming,age=20 where sno=4;
3 
4 --使用子查询进行更新
5 update student set (sname,age) =(select sname,age from student_copy where sno=3) where sno=4;
6 update student set sname=(select sname from student_copy where sno=3),age=(select age from student_copy where sno=4) where sno=3; 
7 update student set sname=(select sname from student_copy where sno=3),age=(select age from student_copy where sno=4);

  3.delete语句:

 1 --删除指定行数据
 2 delete from student where sno=4;
 3 --删除名称为abc的行数据
 4 delete from student where sname=abc
 5 --删除全部数据
 6 delete from student;
 7 
 8 --使用子查询的删除
 9 delete from student where sname=(select sname from student_copy where sno=3);
10 delete from student where sname in (select sname from student_copy);

  4.DQL(数据查询语言)

    数据查询语言有单表查询 ,单表子查询, 多表查询,另写一篇博客详细写。

 

oracle基础

标签:grant   rar   admin   commit   --   运行   匹配   事务控制   一个用户   

原文地址:https://www.cnblogs.com/afel/p/9260699.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!