数据库学习笔记day01+day02
select sysdate from dual
--表是关系型数据库的基本结构
--表是二维的,由行和列组成
--行称为记录,列称为字段
create table hw(
name varchar2(20), --Java中的String数据类型在这里用varchar2,number(6,2)6位中有2位小数
age number(2),
address varchar2(50)
);
desc hw;
drop table hw;
alter table hw modify(name varchar2(15));
alter table hw drop(name);
alter table hw add(Xingming varchar2(20));
rename hw to hw1;
insert into hw (name,age,address) values('李',22,'长清区紫薇阁')
insert into hw (name) values('陈')
select * from hw;
delete hw where name='李';
update hw set age=21 where age is null;
update hw set name='再见' where age is not null;
update hw set name='' where age=null;
--DDL:数据定义语言,操作表头。create table name();drop table name;alter table name motify();
--DML:数据操作语言,操作数据 insert into name() values();delete[from]hw where xxx=xxx;update name set xxx= where yyy=null;
--char&varchar2:char :定长字符,声明多少占用多少,不够的补空格。varchar2变长字符,实际用多少占用多少。
--char最大2000字节,varchar2最大4000个字节,long最大2G,clob最大4G,一张表只能有一个clob。
--concat:将两个字段合成一个字段
empno number(4,0),
ename varchar2(10),
job varchar2(9),
rngr number(4,0),
hiredate date,
sal number(7,2),
comm number(7,2),
deptno number(2,0)
);
insert into emp values(7499,'allen','salesman',7698,to_date('1981/12/20','yyyy-mm-dd'),1600.00,300.00,30);
insert into emp values(7521,'ward','salesman',7698,to_date('1982/2/22','yyyy-mm-dd'),1250.00,500.00,30);
insert into emp values(7566,'jones','manager',7839,to_date('1981/4/2','yyyy-mm-dd'),2975.00,null,20);
insert into emp values(7654,'martin','manager',7698,to_date('1981/9/28','yyyy-mm-dd'),1250.00,1400.00,30);
insert into emp values(7698,'blake','manager',7839,to_date('1981/5/1','yyyy-mm-dd'),2850.00,null,30);
insert into emp values(7782,'clark','manager',7839,to_date('1981/6/9','yyyy-mm-dd'),2450.00,null,10);
insert into emp values(7788,'scott','analyst',7566,to_date('1987/4/19','yyyy-mm-dd'),3000.00,null,20);
insert into emp values(7839,'king','president',null,to_date('1981/11/17','yyyy-mm-dd'),5000.00,null,10);
insert into emp values(7844,'turner','salesman',7698,to_date('1981/9/8','yyyy-mm-dd'),1500.00,0.00,30);
insert into emp values(7876,'adamas','clerk',7788,to_date('1987/5/23','yyyy-mm-dd'),1100.00,null,20);
insert into emp values(7900,'james','clerk',7698,to_date('1981/12/3','yyyy-mm-dd'),950.00,null,30);
insert into emp values(7902,'ford','analyst',7566,to_date('1981/12/3','yyyy-mm-dd'),1300.00,null,20);
insert into emp values(7934,'miller','clerk',7782,to_date('1982/1/23','yyyy-mm-dd'),1300.00,null,10);
commit --提交
select *from emp; --查看表中的内容
select concat(concat(ename,':'),sal)from emp;
select ename||':'||sal from emp; --查看表中enama和sal,并且连接起来
--length 返回字符串的长度
select ename,length(ename)from emp; --查看表中ename表头下的长度
--lower,upper,initcap:转换大小写或者首字母大写。
select lower(ename)from emp; --将enanme属性下的转换为小写并列出
select upper(ename)from emp; --转换为大写
--截去子串/左截去/右截去 : trim/ltrim/rtrim
select trim(7 from empno)from emp; --截去7个
select ltrim('qwer','q')from dual; --从左边截去q
select rtrim('qwer','r')from dual; --从右边截去r
--补位函数 lpad/rpad
select sal from emp;
select lpad(sal,5,'+') from emp; --sal补为五位,sal本身不够的补+
--截取字符 substr('',m,n)从第m个开始,截取n个字符
select substr('Following the track of the gale,I am chasing the sun.',33,25) from dual; --得到I am chasing the sun.
--instr(char1,char2)反回char2在char1中的位置(第几个)
select instr('qwer','w') from dual;
select round(3.1415926,2) from dual;
select round(46.33,-1)from dual;
select trunc(123456,-2)from dual;--个位为-1,十位为-2.
select sal,job from emp;
select ceil(3.18)from dual;
select floor(3.18)from dual;
--查看81年以后入职的都有谁
select sal,ename from emp ;
select ename,job,to_char(hiredate,'yyyy"年"mm"月"dd"日"') from emp;
select last_day(sysdate) from dual;
select last_day(hiredate)from emp;
select add_months(sysdate,10)from dual;
select add_months(hiredate,12*20)from emp;
select round(months_between(sysdate,to_date('1997-07-1','yyyy-mm-dd')))from dual;
select round(months_between(to_date('2097-11-6','yyyy-mm-dd'),sysdate))from dual;
select round(months_between(add_months(to_date('1997-11-6','yyyy-mm-dd'),12*100),sysdate))from dual;
select next_day(sysdate,1)from dual;
--查看员工每个月领走多少钱
select ename,sal,comm,nvl2(comm,sal+comm,sal)from emp;
select ename e,job j from emp;
select *from emp where deptno=10 ;
--谁是经理
--谁的薪资大于两千
select *from emp where sal>2000;
select *from emp where sal>2000 and job='manager';
select *from emp where deptno=20 and hiredate>to_date('1981-01-01','yyyy-mm-dd'); ---**
select *from emp where ename like '_a%';
select *from emp where job like '%na%';
select * from emp where job not in ('manager','clerk');
select * from emp where job !='manager' and job !='clerk';
select *from emp where hiredate between to_date('1981-01-01','yyyy-mm-dd')and to_date('1982-12-31','yyyy-mm-dd');
select *from emp where sal >any(1500,3000)and sal <any(1500,3000);
select distinct(ename) from emp;
数据库学习笔记day01+day02的更多相关文章
- MySQL数据库学习笔记(十二)----开源工具DbUtils的使用(数据库的增删改查)
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...
- MySQL数据库学习笔记(十)----JDBC事务处理、封装JDBC工具类
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...
- MySQL数据库学习笔记(九)----JDBC的ResultSet接口(查询操作)、PreparedStatement接口重构增删改查(含SQL注入的解释)
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...
- Mysql数据库学习笔记之数据库索引(index)
什么是索引: SQL索引有两种,聚集索引和非聚集索引,索引主要目的是提高了SQL Server系统的性能,加快数据的查询速度与减少系统的响应时间. 聚集索引:该索引中键值的逻辑顺序决定了表中相应行的物 ...
- MYSQL数据库学习笔记1
MYSQL数据库学习笔记1 数据库概念 关系数据库 常见数据库软件 SQL SQL的概念 SQL语言分类 数据库操作 创建数据库 查看数据库的定义 删除数据库 修改数据库 创建表 数据类型 约束 ...
- [转]mnesia数据库学习笔记
mnesia数据库学习笔记一 mnesia数据库学习笔记二 mnesia数据库学习笔记三 mnesia数据库学习笔记四
- 数据库学习笔记3 基本的查询流 2 select lastname+','+firstname as fullname order by lastname+','+firstname len() left() stuff() percent , select top(3) with ties
数据库学习笔记3 基本的查询流 2 order by子句对查询结果集进行排序 多列和拼接 多列的方式就很简单了 select firstname,lastname from person.pers ...
- Caché数据库学习笔记(5)
目录 Cache数据库方法的RESTful封装 ================================================================ 因为对web serv ...
- MySQL数据库学习笔记(八)----JDBC入门及简单增删改数据库的操作
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...
随机推荐
- Selenium+Java(六)Selenium 强制等待、显式等待、隐实等待
前言 在实际测试过程中,由于网速或性能方面的原因,打开相应的网页后或在网页上做了相应的操作,网页上的元素可能不会马上加载出来,这个时候需要在定位元素前等待一下,等元素加载出来后再进行定位,根据实际使用 ...
- 【RN - 基础】之View使用简介
简介 View是一个容器,支持FlexBox布局. View既可以作为容器容纳其他组件,也可以作为一个组件包含进另一个容器中. 无论运行在哪个平台上,View都会直接对应这个平台的原生视图,如iOS中 ...
- 队列&生产者消费者模型
队列 ipc机制:进程通讯 管道:pipe 基于共享的内存空间 队列:pipe+锁 queue from multiprocessing import Process,Queue ### 案例一 q ...
- Linux命令行初学(一)
linux命令大全:https://www.linuxcool.com/ 大概了解到有哪些命令,如果有需要的话可以在该网站上查询. 另外在实验楼学习了一些基础,该篇博客就此次对linux命令行的学习进 ...
- Magicodes.Sms短信库的封装和集成
简介 Magicodes.Sms是心莱团队封装的短信服务库,已提供Abp模块的封装. Nuget 新的包 名称 说明 Nuget Magicodes.Sms.Aliyun 阿里云短信库 Magicod ...
- 为什么查询出来的数据保存到Arraylist?插入删除数据为啥用LinkedList?
引言:这是我在回答集合体系时,被问到的一个问题,也是因为没有深入学习所以回答的并不是很好,所以这两天看了一下,以下是我的一些回答与学习方法. 学习方法:我们学习,系统性的学习肯定是比零散的学习更有效的 ...
- 2017 CCPC秦皇岛 A题 A Ballon Robot
The 2017 China Collegiate Programming Contest Qinhuangdao Site is coming! There will be teams parti ...
- Dijkstra(迪杰斯特拉求最短路径)-02-网络延迟时间
有 N 个网络节点,标记为 1 到 N. 给定一个列表 times,表示信号经过有向边的传递时间. times[i] = (u, v, w),其中 u 是源节点,v 是目标节点, w 是一个信号从源节 ...
- 递归的实际业务场景之MySQL 递归查询
喜欢就点个赞呗! 源码<--请点击此处查看 引入 当我看到一些评论时,例如下面的样子.我挺好奇这个功能是怎么样做出来的.进过查阅资料,发现这其实是 MySQL 的递归操作.下面就让我操作一下怎么 ...
- 函数计算: 让小程序开发进入 Serverless 时代
点击下载<不一样的 双11 技术:阿里巴巴经济体云原生实践> 本文节选自<不一样的 双11 技术:阿里巴巴经济体云原生实践>一书,点击上方图片即可下载! 作者 | 吴天龙(木吴 ...