数据库学习笔记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 ...
随机推荐
- Spring(Bean)5
spel <bean id="address" class="com.atguigu.spring.beans.spel.Address"> < ...
- linux免密登录和设置别名
一.免密登录 (1) 配置公钥 ssh-keygen (2)让远程服务器记住公钥 ssh-copy-id 用户名@ip地址或域名 二.设置别名 (3)在~/.ssh目录下创建并编辑conf ...
- FastAdmin的基本使用
FastAdmin是一款基于ThinkPHP5+Bootstrap的极速后台开发框架. 1.在线命名管理 (1)菜单的生成 (2)一键 crud 首先要安装在线命名 在翡翠分类生成菜单,如下: 它的 ...
- Spring Cloud Hoxton正式发布,Spring Boot 2.2 不再孤单
距离Spring Boot 2.2.0的发布已经有一个半月左右时间,由于与之匹配的Spring Cloud版本一直没有Release,所以在这期间碰到不少读者咨询的问题都是由于Spring Boot和 ...
- 补习系列(20)-大话 WebSocket 与 "尬聊"的实现
目录 一.聊聊 WebSocket 二.Stomp 是个什么鬼 三.SpringBoot 整合 WebSocket A. 引入依赖 B. WebSocket 配置 C. 控制器 D. 前端实现 四.参 ...
- Android Selector和Shape的用法
一.Shape的用法 :shape用于设定形状,可以在selector,layout等里面使用,有6个子标签,各属性如下: 填充:设置填充的颜色 间隔:设置四个方向上的间隔 大小:设置大小 圆角:同时 ...
- vue 常用的官网
vue.js https://cn.vuejs.org/ v-charts https://v-charts.js.org/#/ (图表,地图) web ...
- BOM和DOM操作
目录 BOM window对象 window子对象 location 弹出框 计时 history navigator DOM 查找节点 直接查找 间接查找 节点操作 创建节点 添加节点 删除节点 替 ...
- 【MySQL】ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
问题现象: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) 拒绝访问root用户 ...
- 文件(图片)转base64
普通图片转base64 function getBase64(url, callback){ var canvas = document.createElement('canvas'),//创建can ...