• oracle基础


    一、Oracle安装

    1.windows10安装oracle

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

    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 1.创建临时表空间
     2 create temporary tablespace temptest 
     3 tempfile 'd:/dbtest/temptest.dbf' size 50m
     4 autoextend on next 100m 
     5 maxsize 1024m extent management local;
     6 2.创建数据表空间
     7 SQL> create tablespace datatest 
     8   2  datafile 'd:/dbtest/datatest.dbf'
     9   3  size 100m
    10   4  autoextend on next 100m
    11   5  maxsize 1024m
    12   6  extent management local autoallocate
    13   7  segment space management auto;
    14 3.创建用户,给用户指定默认表空间和临时表空间
    15 SQL> create user test identified by test
    16   2  default tablespace datatest
    17   3  temporary tablespace temptest;
    18 4.给用户授权
    19 grant connect,resource to test;
    20 5.收回赋予用户的权限
    21 revoke connect,resource from test;

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

     1 create user test1 identified by test1;
     2 
     3 create user test2 identified by test2;
     4 
     5 connect / as sysdba;
     6 
     7 grant connect,resource to test1 with admin option;
     8 
     9 connect test1/test1;
    10 
    11 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(数据查询语言)

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

  • 相关阅读:
    到底如何设置 Java 线程池的大小?
    面试一个 3 年 Java 程序员,一个问题都不会!
    Spring Boot 集成 Ehcache 缓存,三步搞定!
    牛逼哄哄的 "零拷贝" 是什么?
    一个 Java 字符串到底有多少个字符?
    不用找了,300 分钟帮你搞定 Spring Cloud!
    五分钟搞懂 Linux 重点知识,傻瓜都能学会!
    如何设计一个完美的权限管理模块?
    Redis基础都不会,好意思出去面试?
    .net c# MVC提交表单的4种方法
  • 原文地址:https://www.cnblogs.com/afel/p/9260699.html
Copyright © 2020-2023  润新知