首页 > 数据库 >a、Oracle基础教程

a、Oracle基础教程

时间:2023-08-13 09:22:07浏览次数:37  
标签:comment column -- VARCHAR2 基础教程 Oracle table

Oracle教程

参考文档:
FreeIT教程
w3cschool教程
《Oracle从入门到精通(第3版) 明日科技》

目录

本篇章主要介绍Oracle的基础教程,本文适合那些刚刚要学习Oracle的初学者或者是想了解Oracle的用户,通过本篇幅可以快速学习Oracle数据库的基础理论。本文通过讲解Oracle基础理论知识,让大家快速的了解Oracle,并通过实例演示,让你更有介入感,能够快速上手,而不仅仅只保留在理论知识上。本篇章的主要内容如下:

  • 1、Oracle介绍:介绍了Oracle数据库应用场景和发展历史,Oracle的平台支持,Oracle的技术特点,orale的相关体系结构。
  • 2、Oracle安装:详细介绍Oracle11g安装过程,教你一步一步搭建Oracle数据库。
  • 3、Oracle客户端工具:介绍Oracle客户端工具(sqlplus)如何使用和plsql developer工具应用和下载。
  • 4、Oracle服务:介绍Oracle11g安装完毕后各个服务的详细作用。
  • 5、Oracle用户:介绍Oracle用户的创建和用户权限、数据库角色的概念以及授权语句的编写。
  • 6、Oracle表介绍:介绍Oracle表的创建查询插入更新删除操作。
  • 7、Oracle运算符介绍:介绍Oracle运算符的运用,其中算术运算、关系和逻辑运算符的实际应用。
  • 8、Oracle系统关键字:如Oracle字符串连接符||DISTINCT去重符Oracle条件查询中的=、in、like、between...and等。
  • 9、Oracle集合运算:Oracle集合运算就是把多个查询结果组合成一个查询结果,oralce的集合运算包括:INTERSECT(交集)、UINION ALL(交集不重复)、UINION(交集)、MINUS(补集)。
  • 10、Oracle连接查询:oralce连接查询是用来进行表间关联的,包含内关联(inner jion )和外关联(outer join),其中外关联又分为左外关联(left outer join)、右外关联(right outer join)和全外连接(full join),其中外关联可以使用(+)来表示。
  • 11、Oracle伪列:rowid、rownum。它们是Oracle表在存储的过程中或查询的过程中,表会有一些附加列,称为伪列。伪列就像表中的字段一样,但是表中并不存储。伪列只能查询,不能增删改。
  • 12、Oracle内置函数:Oracle内置函数包括Oracle字符型函数Oracle日期函数Oracle数值型函数Oracle转换函数Oracle聚合函数的介绍。
  • 13、Oracle子查询:Oracle子查询就是嵌套查询,他把select 查询的结果作为另外一个select、update或delete语句的条件,它的本质就是where条件查询中的一个条件表达式。
  • 14、Oracle同义词:Oracle synonym 同义词是数据库当前用户通过给另外一个用户的对象创建一个别名,然后可以通过对别名进行查询和操作,等价于直接操作该数据库对象。
  • 15、Oracle序列:Oracle序列Sequence是用来生成连续的整数数据的对象,它经常用来作为业务中无规则的主键。Oracle序列可以是升序列也可以是降序列。
  • 16、Oracle视图:oracle视图可以理解为数据库中一张虚拟的表,他是通过一张或者多张基表进行关联查询后的结果组成一个虚拟的表。查询视图,本质上是对表进行关联查询。
  • 17、Oracle索引:Oracle索引(index)最大的作用是来优化数据库查询的效率,提升数据库的查询性能。就好比书的目录一样,可以通过目录来直接定位所需内容存在的页数,大大提高检索效率。

案例所需表结构

该Oracle基础教程所有案例所需的表结构是利用Oracle技术圈自己设计的一套简单版的学生信息系统的表结构。相关表结构的关系图如下:


表结构执行脚本:

-- Create table
create table STUINFO
(
  stuid      VARCHAR2(11) not null,
  stuname    VARCHAR2(50) not null,
  sex        CHAR(1) not null,
  age        NUMBER(2) not null,
  classno    VARCHAR2(7) not null,
  stuaddress VARCHAR2(100) default '地址未录入',
  grade      CHAR(4) not null,
  enroldate  DATE,
  idnumber   VARCHAR2(18) default '身份证未采集' not null
)
tablespace USERS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
-- Add comments to the table 
comment on table STUINFO
  is '学生信息表';
-- Add comments to the columns 
comment on column STUINFO.stuid
  is '学号';
comment on column STUINFO.stuname
  is '学生姓名';
comment on column STUINFO.sex
  is '学生性别';
comment on column STUINFO.age
  is '学生年龄';
comment on column STUINFO.classno
  is '学生班级号';
comment on column STUINFO.stuaddress
  is '学生住址';
comment on column STUINFO.grade
  is '年级';
comment on column STUINFO.enroldate
  is '入学时间';
comment on column STUINFO.idnumber
  is '身份证号';
-- Create/Recreate primary, unique and foreign key constraints 
alter table STUINFO
  add constraint PK_STUINFO primary key (STUID)
  using index 
  tablespace USERS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
  
  -- Create table
create table CLASS
(
  classno        VARCHAR2(7) not null,
  classname      VARCHAR2(50),
  monitorid      VARCHAR2(11),
  monitorname    VARCHAR2(50),
  headmasterid   VARCHAR2(8),
  headmastername VARCHAR2(50),
  classaddress   VARCHAR2(50),
  enterdate      DATE
)
tablespace USERS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );
-- Add comments to the table 
comment on table CLASS
  is '班级信息表';
-- Add comments to the columns 
comment on column CLASS.classno
  is '班级号';
comment on column CLASS.classname
  is '班级名称';
comment on column CLASS.monitorid
  is '班长学号';
comment on column CLASS.monitorname
  is '班长姓名';
comment on column CLASS.headmasterid
  is '班主任教师号';
comment on column CLASS.headmastername
  is '班主任姓名';
comment on column CLASS.classaddress
  is '班级地址';
comment on column CLASS.enterdate
  is '录入时间';
-- Create/Recreate primary, unique and foreign key constraints 
alter table CLASS
  add constraint PK_CLASS primary key (CLASSNO)
  using index 
  tablespace USERS
  pctfree 10
  initrans 2
  maxtrans 255;


-- Create table
create table COURSE
(
  courseid   VARCHAR2(9) not null,
  schyear    VARCHAR2(4),
  term       VARCHAR2(4),
  coursename VARCHAR2(100)
)
tablespace USERS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
-- Add comments to the table 
comment on table COURSE
  is '课程表';
-- Add comments to the columns 
comment on column COURSE.courseid
  is '课程id';
comment on column COURSE.schyear
  is '学年';
comment on column COURSE.term
  is '学期';
comment on column COURSE.coursename
  is '课程名称';
-- Create/Recreate primary, unique and foreign key constraints 
alter table COURSE
  add constraint PK_COURSE primary key (COURSEID)
  using index 
  tablespace USERS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
  
  -- Create table
create table STUCOURSE
(
  selectid   VARCHAR2(18) not null,
  stuid      VARCHAR2(11),
  courseid   VARCHAR2(9),
  schyear    VARCHAR2(4),
  term       VARCHAR2(4),
  redo       VARCHAR2(1),
  selectdate DATE
)
tablespace USERS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );
-- Add comments to the table 
comment on table STUCOURSE
  is '学生选课表';
-- Add comments to the columns 
comment on column STUCOURSE.selectid
  is '选课id';
comment on column STUCOURSE.stuid
  is '学号';
comment on column STUCOURSE.courseid
  is '课程id';
comment on column STUCOURSE.schyear
  is '年度';
comment on column STUCOURSE.term
  is '学期';
comment on column STUCOURSE.redo
  is '是否重修';
comment on column STUCOURSE.selectdate
  is '选课时间';
-- Create/Recreate primary, unique and foreign key constraints 
alter table STUCOURSE
  add constraint PK_STUCOURSE primary key (SELECTID)
  using index 
  tablespace USERS
  pctfree 10
  initrans 2
  maxtrans 255;


-- Create table
create table SCORE
(
  scoreid  VARCHAR2(18) not null,
  stuid    VARCHAR2(11),
  courseid VARCHAR2(9),
  score    NUMBER,
  scdate   DATE
)
tablespace USERS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
-- Add comments to the table 
comment on table SCORE
  is '学生成绩表';
-- Add comments to the columns 
comment on column SCORE.scoreid
  is '学生成绩id';
comment on column SCORE.stuid
  is '学生学号';
comment on column SCORE.courseid
  is '课程id(年度+上下学期+课程序列)';
comment on column SCORE.score
  is '成绩';
comment on column SCORE.scdate
  is '成绩录入时间';
-- Create/Recreate primary, unique and foreign key constraints 
alter table SCORE
  add constraint PK_SCORE primary key (SCOREID)
  using index 
  tablespace USERS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

标签:comment,column,--,VARCHAR2,基础教程,Oracle,table
From: https://www.cnblogs.com/simpleness/p/17626151.html

相关文章

  • kylin v10 安装 Oracle 19c/12c遇到问题汇总
    适用范围麒麟_v10_sp1_20200711Oracle19c/12c银河麒麟V10sp1内核版本redhat8.6内核版本遇到问题19c问题1PRVG-0282:failedtoretrievetheoperatingsystemdistributionIDOracle是不支持在银河麒麟上安装的,但由于银河麒麟也属于redhat系,我们就能伪装自己是redhat系统,从......
  • oracle归档日志暴增原因分析,Oracle归档日志满导致数据库性能异常慢 转发 https://b
    ============= oracle数据库archivelog暴增分析====================前言归档量突然增长到981G/天,导致归档目录使用率告警归档日志量异常暴增会导致磁盘空间爆满,数据库异常1、归档日志量统计SELECTTRUNC(FIRST_TIME)"TIME",SUM(BLOCK_SIZE*BLOCKS)/1024/1024/102......
  • Oracle-快速恢复区
    快速恢复区是一个磁盘目标,用作与恢复相关的文件的默认位置。可以使用两个实例参数对快速恢复区进行控制:db_recovery_file_destdb_recovery_file_dest_size第一个参数指定位置。这可以是文件系统目录或ASM磁盘组。多个数据库可以共享一个公共目标;在目标中,每个数据库都有各自自动创......
  • 数据库数据恢复-Oracle ASM数据恢复案例
    数据库数据恢复环境:Oracle数据库ASM磁盘组有4块成员盘。数据库故障&分析:Oracle数据库ASM磁盘组掉线,ASM实例无法挂载,用户联系我们要求恢复oracle数据库。数据库数据恢复工程师拿到磁盘后,先将所有磁盘以只读方式进行扇区级别的镜像备份,后续的数据分析和数据恢复都基于镜像文件进......
  • 【Oracle】 insert performance issue
    https://blog.iarsov.com/oracle/insert-statement-taking-long-time/--->https://blog.iarsov.com/oracle/sequences-cache-nocache/......
  • DB2和 Oracle的并发控制(锁)比较
    2005年12月26日在实际的生产运行环境中,笔者在国内很多客户现场都看到开发人员和系统管理人员遇到很多有关于锁而引起的性能问题,进而被多次问起DB2和Oracle中锁的区别比较问题,笔者根据自己在工作中对DB2和Oracle数据库的使用经验积累写下这篇文章。<!--startRESERVED......
  • oracle 设置数据层次
    OracleLevel函数:简单易用的多层级查询利器在数据库操作中,常常需要查询多层级的数据,比如树形菜单、组织架构等等。在Oracle数据库中,我们可以利用Level函数来实现多层级查询,这个函数的使用非常简单,下面就让我们来了解一下。1.什么是Level函数?Level函数是Oracle数据库中内置的一种函......
  • 【Oracle】获取指定用户所有表的建表语句
    #!/bin/bashTBL_LIST=/tmp/table_name_list.outTBL_METADATA=/tmp/ddl_tables_all.sqlsqlplus-S'/assysdba'<<EOFPROMPTspool${TBL_LIST}setpages0setechooffheadingofffeedbackoffselectusernamefromdba_userswhereusernamen......
  • Oracle 安装 Failed to Create oracle Oracle Home User 解决方案
    WindowsServer2016安装Oracle12报错:FailedtoCreateoracleOracleHomeUser的解决方案:1、打开域安全策略(secpol.msc)-安全设置-账户策略-密码策略-密码必须符合复杂性要求。定义这个策略设置为:已禁用。 2、最后cmd运行刷新组策略命令为:gpupdate/force 3、重新......
  • 设置Oracle视图查询权限的步骤(oracle视图查询权限)
    设置Oracle视图查询权限的步骤是向用户授予SELECT对设定视图的权限。Oracle提供了两种主要方式来授予用户查询视图的权限,分别是直接授权和使用角色授权。本文将介绍如何正确地设置授权,使用Oracle视图。 首先,要设置Oracle视图查询权限,必须具有包括CREATEVIEW权限和SELECT权限的......