Oracle数据库基础(二)
1.表名命名规则:必须以字母开头,不能超过30个字符,不要有Oracle保留字
2.数据类型
字符型:
char :2000个字符 定长 效率高
varchar2:4000个字符 变长
Clob:字符型大对象 4G
数字型:
number 范围:-10^38~10^38
sal number(5) -99999~99999
sal number(7,2) -99999.99~99999.99 7位有效数字,2位小数
日期类型:
date 年月日 时分秒
timesatmp 对date类型的拓展 毫秒
图片
blob 二进制数据 存放图片,音频等
一般不对图片和音频进行存储,而是存储其路径
3.建表语句
create table student(id number(2),name varchar2(10),sex
char(4),birthday date,sal number(7,2),comm number(3),class_number
number(2));
添加字段:
alter table tableName add(字段名 数据类型(长度)))
alter table student add(score number(3));
修改字段长度/数据类型/字段名(前提:保证修改的表内不能存数据)
alter table tableName modify(字段名 数据类型(长度));
alter table student modify(comm number(4));
alter table student modify(class_number varchar2(4));
删除字段:
alter table tableName drop column 字段名
重命名
rename oldName to newName
rename student to stu
删除表
drop table tableName
4.对数据操作
4.1增加数据:
每个字段都有数据:insert into tableName
(id,name,age,sex,score,sal,comm,class_number,birthday)
values(2,'andy',30,'女',21,567,12,1,'21-2月-92');
修改时间格式:alter session set nls_date_format='yyyy-mm-dd';
部分字段有数据:insert into student(id,name,age,sex,birthday,sal) values(7,'Bob',30,'男','1983-4-24',9483);
inset into student(id,name,age,sex,birthday,sal) values(8,'ku',29,'男','1929-3-12',null);
查找工资为空的人:select * from student where sal is null;
不为 select * from student where sal is not null;
4.2修改数据
修改单个字段:update student set id=2 where name='james';
修改多个字段:update student set score=80,sal=10000 where name='james';
将女性工资下调一半:update student set sal=sal/2 where sex='女';
4.3删除数据
delete from student; 删除所有数据 可回滚
savepoint
rollback to 设置节点,可将删除的操作回滚
truncate table student 不可回滚
drop table student 删除表中数据和表结构
delete froom student where name='ku';
4.4查询数据
查表结构:desc table student;
查询所含有的列:select * from student
查询指定的列: select name from student;
查询多行:select name,age from student;
set timming on;
查询gai的工资和年龄:
select sal,age from student where name='gai';
查询gai的年薪:
select sal*12 from student where name='gai';
给年薪起别名
select sal*12 "年薪" from student where name='gai';
字段拼接:
select name||age from student;
select name||'的年龄是'||age from student;
查询所有同学年终工资:
select name||'工资'||sal*12+comm*12 from student;
(奖金为空,年工资为空)==>
处理null值:nvl(comm,0)*12
select name||'工资'||sal*12+nvl(comm,0)*12 from student;
where字句
查询工资低于5000的学生:
select name from student where sal<=5000;
查询生日在1990-1-1后的学生:
select name from student where birthday>'1990-1-1';
like字句(%可代表0-n个任意字符,_可代表任意单个字符)
select sal,name from student where name like 's%';
in字句:
查询3班所有学生姓名:
select name from student where class_number in 3;
Oracle数据库基础(二)的更多相关文章
- Oracle数据库基础入门《二》Oracle内存结构
Oracle数据库基础入门<二>Oracle内存结构 Oracle 的内存由系统全局区(System Global Area,简称 SGA)和程序全局区(Program Global Ar ...
- Oracle数据库基础入门《一》Oracle服务器的构成
Oracle数据库基础入门<一>Oracle服务器的构成 Oracle 服务器是一个具有高性能和高可靠性面向对象关系型数据库管理系统,也是一 个高效的 SQL 语句执行环境. Oracle ...
- 第一章 oracle数据库基础
第一章 oracle数据库基础 1.oracle简介-->数据库管理系统 1.1:数据库 1.2:全局数据库名 1.3:数据库实例 1.4:表空间 1.5:数据 ...
- Oracle数据库基础知识
oracle数据库plsql developer 目录(?)[-] 一 SQL基础知识 创建删除数据库 创建删除修改表 添加修改删除列 oracle cascade用法 添加删除约束主键外 ...
- Oracle 数据库基础——安装
一.数据库基础知识 1.概念 数据库全称数据库管理系统,简称DBMS,是一种在计算机中,针对数据进行管理.存储.共享的一种技术. 2.分类 数据库的发展过程中,按逻辑模型可分为以下几种: 3.关系型数 ...
- 【学习笔记】Y2-1-1 Oracle数据库基础
Oracle 简介关系型(二维表)数据库 用来存储海量数据在大数据量的并发检索的情况下,性能要高于其他同类数据库产品一般运行环境是Linux和UnixOracle版本中的I(Internet) G(G ...
- Oracle 数据库 基础学习 (一) SQL基本知识
Oracle 从零开始,不知所措.要掌握一种技能,最好的方式是先学会怎么使用它,然后再深入学习,先有样子,再有技术. 一,什么是数据库? 为什么需要数据库? 数据库实质上是一个信息的列表,或者是一 ...
- Oracle数据库 基础SQL语句练习
一.说明 第一次使用Oracle,想做一些练习,熟悉一些oracle. 表:使用的是scott用户,默认的表 具体表讲解,可以参考该文档:https://www.cnblogs.com/xjcheng ...
- Oracle数据库基础教程
Oracle基础 简介 数据库实例 表空间 登录身份和角色 用户和授权 数据类型 数据操作 导入数据库 一.Oracle基础: 1.简介 Oracle创建数据库不能像SQL Server那样用一个简单 ...
- [转载]Oracle数据库基础--SQL查询经典例题
Oracle基础练习题,采用Oracle数据库自带的表,适合初学者,其中包括了一些简单的查询,已经具有Oracle自身特点的单行函数的应用 本文使用的实例表结构与表的数据如下: emp员工表结构如下: ...
随机推荐
- 【Oracle】RAC控制文件多路复用
1.—关闭数据库,各个节点都要关闭: [oracle@rac1 ~]$ srvctl stop database -d racdb -o immediate 2.—启动任一节点到nomount状态: ...
- [转]C++内存管理
[导语] 内存管理是C++最令人切齿痛恨的问题,也是C++最有争议的问题,C++高手从中获得了更好的性能,更大的自由,C++菜鸟的收获则是一遍一遍的检查代码和对C++的痛恨,但内存管理在C++中无处不 ...
- Docker的官网在线--中文教程
1.官网界面:https://www.docker.com/tryit/ In this 10-minute tutorial, see how Docker works first-hand: Yo ...
- 数据的图表统计highcharts
数据统计常用的图表一般是饼状图.柱状图.线状图,HighCharts可以很好的实现. HighCharts highcharts是基于jquery的一个功能强大的插件,使用时先导入jquery.js ...
- What's Dead & Exploded in Swift's exception stack?
The Swift compiler marks function arguments for a number of reasons, mostly related to internal opti ...
- Java中数组获取最大值
最大值获取:从数组的所有元素中找出最大值. 实现思路: 定义变量,保存数组0索引上的元素 遍历数组,获取出数组中的每个元素 将遍历到的元素和保存数组0索引上值的变量进行比较 如果数组元素的值大于了变量 ...
- JSCH实现文件上传下载至sftp服务器
文件服务器采用FreeSSHd,文件服务器配置就不细说了. 直接上代码,该代码可以直接使用. import com.jcraft.jsch.*; import java.io.InputStream; ...
- node——express实现hello world
创建文件夹,在文件夹内再创建index.js 1.package.json npm init -y 2.安装 npm install express ---save 3.index.js //入口文件 ...
- Spring Boot project with static content generates 404 when running jar
转自:http://stackoverflow.com/questions/21358403/spring-boot-project-with-static-content-generates-404 ...
- 洛谷P1055 ISBN号码
题目描述 每一本正式出版的图书都有一个ISBN号码与之对应,ISBN码包括 999 位数字. 111 位识别码和 333 位分隔符,其规定格式如x-xxx-xxxxx-x,其中符号-就是分隔符(键盘上 ...