2022年Oracle数据库基础 .pdf
《2022年Oracle数据库基础 .pdf》由会员分享,可在线阅读,更多相关《2022年Oracle数据库基础 .pdf(15页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Oracle 数据字段的类型和Oracle 中运算符1.oracle 数据字段的主要数据类型数据类型说明char(n)存放定长字符串,最长为2000 个字符nchar(n)最长由数据库使用的字符集决定varchar2(n)存放变长字符串,最长为4000 个字符nVarchar2(n)最长由数据库使用的字符集决定number(l,p)存放数值类型数据。L 长度p 小数位数,最长为38 位.可以用来保存任何数值类型的数据blob 二进制大对象,长度2G Date 存放日期时间,默认格式:DD-MONTH-YY long 存放可变长字符数据。长度2G clob 存放可变长字符数据。长度2G bFil
2、e 存放在数据库外部的大型二进制文件。长度=ALL(Select salary from emp where deptno=30)3Exists 用来检查子查询的结果,如果至少有一行,则返回true,否则,返回false 4双目运算符-可以作用于两个日期相减,返回它们之间相差的天数,可用于计算年龄等例如:select 姓名,ceil(Sysdate-birthday)/365)年龄from men 一、准备数据:例 1 students表结构CREATE TABLE students(student_id NUMBER(5)CONSTRAINT student_pk PRIMARY KEY,m
3、onitor_id NUMBER(5),name VARCHAR2(10)NOT NULL,sex VARCHAR2(6)CONSTRAINT sex_chk CHECK(sex IN(男,女),dob DATE,specialty VARCHAR2(10);例 2 departments表结构CREATE TABLE departments(department_id NUMBER(3)CONSTRAINT department_pk PRIMARY KEY,department_name VARCHAR2(8)NOT NULL,address VARCHAR2(40);例 3 teache
4、rs表结构CREATE TABLE teachers(teacher_id NUMBER(5)CONSTRAINT teacher_pk PRIMARY KEY,name VARCHAR2(8)NOT NULL,名师资料总结-精品资料欢迎下载-名师精心整理-第 2 页,共 15 页 -title VARCHAR2(6),hire_date DATE DEFAULT SYSDATE,bonus NUMBER(7,2),wage NUMBER(7,2),department_id NUMBER(3)CONSTRAINT teachers_fk_departments REFERENCES depa
5、rtments(department_id);例 4 courses表结构CREATE TABLE courses(course_id NUMBER(5)CONSTRAINT course_pk PRIMARY KEY,course_name VARCHAR2(30)NOT NULL,credit_hour NUMBER(2);例 5 students_grade表结构CREATE TABLE students_grade(student_id NUMBER(5)CONSTRAINT students_grade_fk_students REFERENCES students(student_
6、id),course_id NUMBER(5)CONSTRAINT students_grade_fk_courses REFERENCES courses(course_id),score NUMBER(4,1);例 6 grades表结构CREATE TABLE grades(grade_id NUMBER(1)CONSTRAINT grade_pk PRIMARY KEY,low_score NUMBER(4,1),high_score NUMBER(4,1),grade VARCHAR2(6);二查看表结构DESCRIBE;例 1 查看 students表结构DESCRIBE stud
7、ents;例 2 查看 teachers表结构DESCRIBE teachers;名师资料总结-精品资料欢迎下载-名师精心整理-第 3 页,共 15 页 -例 3 查看 departments 表结构DESCRIBE departments;例 4 查看 courses 表结构DESCRIBE courses;例 5 查看 students_grade表结构DESCRIBE students_grade;例 6 查看 Grades 表结构DESCRIBE grades;三删除表及其结构DROP TABLE;例 1 删除 teachers表。DROP TABLE teachers;例 2 删除
8、departments 表。DROP TABLE departments;例 3 删除 students_grade表。DROP TABLE students_grade;例 4 删除 students表。DROP TABLE students;例 5 删除 courses 表。DROP TABLE courses;例 6 删除 grades表。DROP TABLE grades;四向表中添加数据INSERT INTO VALUES(字段值);要求字段值必须与字段名顺序,类型相同INSERT INTO(字段名)VALUES(字段值);例 1 添加 students记录学生记录:INSERT I
9、NTO students VALUES(10101,NULL,王晓芳,女,07-5 月-1988,计算机);名师资料总结-精品资料欢迎下载-名师精心整理-第 4 页,共 15 页 -INSERT INTO students VALUES(10205,NULL,李秋枫,男,25-11 月-1990,自动化);INSERT INTO students VALUES(10102,10101,刘春苹,女,12-8 月-1991,计算机);INSERT INTO students VALUES(10301,NULL,高山,男,08-10 月-1990,机电工程);INSERT INTO students
10、 VALUES(10207,10205,王刚,男,03-4 月-1987,自动化);INSERT INTO students VALUES(10112,10101,张纯玉,男,21-7 月-1989,计算机);INSERT INTO students VALUES(10318,10301,张冬云,女,26-12 月-1989,机电工程);INSERT INTO students VALUES(10103,10101,王天仪,男,26-12 月-1989,计算机);INSERT INTO students VALUES(10201,10205,赵风雨,男,25-10 月-1990,自动化);IN
11、SERT INTO students VALUES(10105,10101,韩刘,男,3-8 月-1991,计算机);INSERT INTO students VALUES(10311,10301,张杨,男,08-5 月-1990,机电工程);INSERT INTO students VALUES(10213,10205,高淼,男,11-3 月-1987,自动化);INSERT INTO students VALUES(10212,10205,欧阳春岚,女,12-3 月-1989,自动化);INSERT INTO students VALUES(10314,10301,赵迪帆,男,22-9 月
12、-1989,机电工程);INSERT INTO students VALUES(10312,10301,白菲菲,女,07-5 月-1988,机电工程);学生记录(NULL):INSERT INTO students VALUES(10328,10301,曾程程,男,NULL,机电工程);INSERT INTO students VALUES(10128,10101,白昕,男,NULL,计算机);INSERT INTO students VALUES(10228,10205,林紫寒,女,NULL,自动化);例 2 添加 departments 记录系部记录:INSERT INTO departm
13、ents V ALUES(101,信息工程,1 号教学楼);INSERT INTO departments V ALUES(102,电气工程,2 号教学楼);INSERT INTO departments V ALUES(103,机电工程,3 号教学楼);连接查询时使用:名师资料总结-精品资料欢迎下载-名师精心整理-第 5 页,共 15 页 -INSERT INTO departments V ALUES(104,工商管理,4 号教学楼);例 3 添加 teachers记录教师记录:INSERT INTO teachers VALUES(10101,王彤,教授,01-9 月-1990,1000
14、,3000,101);INSERT INTO teachers VALUES(10104,孔世杰,副教授,06-7 月-1994,800,2700,101);INSERT INTO teachers VALUES(10103,邹人文,讲师,21-1 月-1996,600,2400,101);INSERT INTO teachers VALUES(10106,韩冬梅,助教,01-8 月-2002,500,1800,101);INSERT INTO teachers VALUES(10210,杨文化,教授,03-10 月-1989,1000,3100,102);INSERT INTO teache
15、rs VALUES(10206,崔天,助教,05-9 月-2000,500,1900,102);INSERT INTO teachers VALUES(10209,孙晴碧,讲师,11-5 月-1998,600,2500,102);INSERT INTO teachers VALUES(10207,张珂,讲师,16-8 月-1997,700,2700,102);INSERT INTO teachers VALUES(10308,齐沈阳,高工,03-10 月-1989,1000,3100,103);INSERT INTO teachers VALUES(10306,车东日,助教,05-9 月-20
16、01,500,1900,103);INSERT INTO teachers VALUES(10309,臧海涛,工程师,29-6 月-1999,600,2400,103);INSERT INTO teachers VALUES(10307,赵昆,讲师,18-2 月-1996,800,2700,103);教师记录(NULL):INSERT INTO teachers VALUES(10128,王晓,NULL,05-9 月-2007,NULL,1000,101);INSERT INTO teachers VALUES(10328,张笑,NULL,29-9 月-2007,NULL,1000,103);
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年Oracle数据库基础 2022 Oracle 数据库 基础
限制150内