范围,查询,升降序
主流数据库
-
关系型数据库:MySQL、oracle、SQLserver、db2…
(1)关系:面向对象 java
(2)数据库表 行 列 java bean
面向对象 一个对象 属性
(3)oracle 10g/11g grid网格计算 -
非关系型数据库:MongoDB 没有表!!都是K:V(键值对)
-
select * from emp;
查询emp表中数据内容
-
select * from tab;
查看该用户下所有表
-
select * from emp where sal between 1000 and 2000;
查询emp表中工资在1000-2000的所有对象
-
set linesize 120
设置行的大小为120
-
set pagesize 50
设置一页能展示的最大数据
-
desc emp;
查看表结构
-
host cls
清屏
-
select empno,ename,job from emp ;
查询表的指定列的数据
-
起别名:as可以省略, " "引号不要省略,避免别名中有空格或者特殊字符
范围查询 between and
-
数字范围:从小到大
selcet * from emp where sal between 100 and 2000 ;
-
日期范围:使用单引号‘’
selcet * from emp where hiredate between ‘17-12月-80’ and ‘23-1月-82’ ;
模糊查询 like , _或者%
-
“_” 一个字符
“%” 任意字符
-
select * from emp where empno like ‘73%’;
以73开头的员工号
-
select * from emp where empno like ‘7%4’;
开头是7,结尾是4的员工号
-
select * from emp where ename like ‘_A%’;
第二个字母是A的员工姓名
-
select * from emp where ename like ‘%N%’;
含N的员工名字
-
select * from emp where ename like ‘_____%’;
名字长度大于5为位的
-
转义字符:转译关键字:escape
注: 转义字符可以是任意字符 但是一般都用“\”
-
In 包含
select * from emp where deptno in(10,20,30,null) ;
查询emp表中所有= (10or20or30or null)的所有数据
-
not in 不包含
select * from emp where deptno not in(10,20,30,null) ;
Not in 就是 in取反 !
查询emp表中所有!= (10and20and30 and null)的所有数据
排序
-
升序:默认/asc
-
降序:desc
注: 在降序中如果有null的话,null在最前面,因为null最大,如果把null放在最后,加上”nulls last ”
补充
-
dual表:用于学习和测试是用的临时表,特点是单行,但是不一定单列
-
a命令:用于追加上一条命令,最后一"/"确认
注意:在语句最后";"分号之前加空格
1 select * from emp ;
2 a order by sal ;
1 * select * from emp order by sal
3 /
) -
c命令:change或者ed
1 c/foom/from
2 /
字符函数
-
Lower、upper、initcap(首字母大写)
-
substr
-
length字符数 / lengthb 字节数
注: GBK: 2个byte定义一个汉字
UTF8:3个byte定义一个汉字
-
instr(str,substr); 在str中找substr的位置
-
lpad(str,len,substr)/rpad(str,len,substr) 左填充/右填充
-
trim:删除字符串两边的任意字符
-
replace(‘hello’,‘e’)替换字符