数据库学习笔记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 ...
随机推荐
- Tensorflow常用函数说明
1.矩阵操作 1.1矩阵生成 这部分主要将如何生成矩阵,包括全0矩阵,全1矩阵,随机数矩阵,常数矩阵等 sess=tf.InteractiveSession() #x=tf.ones([2,3],tf ...
- Java多线程面试题:线程锁+线程池+线程同步等
1.并发编程三要素? 1)原子性 原子性指的是一个或者多个操作,要么全部执行并且在执行的过程中不被其他操作打断,要么就全部都不执行. 2)可见性 可见性指多个线程操作一个共享变量时,其中一个线程对变量 ...
- vue 中使用 watch 的各种问题
报错: Method "watch" has type "object" in the component definition. Did you refere ...
- PHP按二维数组中的某个值重新排序数组 usort的使用方法
$arr[0] = ['aa'=>123,'bb'=>'abc']; $arr[1] = ['aa'=>456,'bb'=>'dfe']; usort($arr,ss('aa' ...
- 【LiteOS】STM32F103-LiteOS移植教程(详细篇)【华为云技术分享】
版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/devcloud/article/detai ...
- shell 文本单词计数
words.txt中的内容如下: the day is sunny the the the sunny is is 统计每个单词出现的次数,并降序输出. Unix Pipes脚本如下: cat wor ...
- HTTP/2简介
1.HTTP/2的定义: HTTP/2即超文本传输协议2.0,是HTTP/1.1下一代的协议.是由互联网工程任务组(IETF)的Hypertext Transfer Protocol Bis (htt ...
- POJ1743 Musical Theme (后缀数组 & 后缀自动机)最大不重叠相似子串
A musical melody is represented as a sequence of N (1<=N<=20000)notes that are integers in the ...
- springboot中实现kafa指定offset消费
kafka消费过程难免会遇到需要重新消费的场景,例如我们消费到kafka数据之后需要进行存库操作,若某一时刻数据库down了,导致kafka消费的数据无法入库,为了弥补数据库down期间的数据损失,有 ...
- 【JS】304- KOA2框架原理解析和实现
); , () => { ); 实现koa的第一步就是对以上的这个过程进行封装,为此我们需要创建application.js实现一个Application类的构造函数: ); , () ...