一、Mysql的函数1、常见的#查询所有列select*fromemp;#只查ename这个字段的值selectenamefromemp;#upper函数用来把值全转大写sele
一、Mysql的函数 1、常见的 select * from emp;
select ename from emp;
select ename, upper( ename) from emp;
select ename, lower( ename) from emp;
select ename, length( ename) from emp
select ename, substr( ename, 1 , 2 ) , substr( ename, 2 , 3 ) from emp
select ename, concat( ename, 'xyz' ) from emp
select ename, replace ( ename, 'a' , 'b' ) from emp
select comm, round ( comm) , ceil( comm) , floor( comm) from emp
select now ( ) select curdate( ) select curtime( )
select now ( ) , year ( now ( ) ) , month ( now ( ) ) , day ( now ( ) ) , hour ( now ( ) ) , minute ( now ( ) ) , second ( now ( ) )
select 'abc\'d'
2、条件查询 select job from empselect distinct job from emp
select * from emp where empno= 100 select * from emp where ename= 'tony'
select * from emp where job= '员工'
select * from emp where job= '员工' and empno= 500
select * from emp where job= '员工' or job= '副总'
select * from emp where 1 = 1
select * from emp where ename like 'a%' select * from emp where ename like '%a%' select * from emp where ename like '%a' select * from emp where ename like 'l%' select * from emp where ename like 'l__'
select * from emp where mgr is null select * from emp where mgr is not null
select * from emp where sal>&#61; 3000 and sal<&#61; 10000 select * from emp where sal between 3000 and 10000
select * from emp limit 1 select * from emp limit 0 , 2 select * from emp limit 1 , 3
select * from emp order by sal select * from emp order by sal asc select * from emp order by sal desc
select * from emp order by ename
3、聚合函数 select * from empselect count ( * ) from emp
select count ( * ) from emp where job &#61; &#39;员工&#39; select count ( mgr) from emp
select count ( 1 ) from emp
select max ( sal) , min ( sal) , sum ( sal) , avg ( sal) from emp;
select comm, ifnull( comm, 0 ) from emp
select ename, sal, comm, sal* 12 &#43; comm* 12 from empselect ename, sal, comm, sal* 12 &#43; ifnull( comm, 0 ) * 12 from empselect ename, sal, comm, sal* 12 &#43; ifnull( comm, 0 ) * 12 as 年薪 from emp
4、分组 select max ( sal) from emp select deptno from emp group by deptno
select deptno, max ( sal) from emp group by deptno
select job, max ( sal) from emp group by job
select mgr, avg ( comm) from emp group by mgr having mgr is not null
select avg ( sal) A from emp group by deptno having A< 8000
二、Oracle数据库 1、和Mysql的对比 1.1 管理库的方式不同: Mysql--数据库--表--记录Oracle--用户--表--记录
1.2 数据类型不同: Mysql--int double varcharOracle--number(8,2)m是数据的长度n小数的位数--varchar2()优化了mysqlvarchar
1.3 语法上的区别: Oracle和Mysql都支持简单的SQL语句,Oracle提供了更丰富 的函数
1.4 更大的区别 MySQL免费版 &#43; 适合分布式架构Oracle收费的
2、Oracle的使用 2.1 安装Oracle的服务器端 10g 11g 12g… OracleXEUniv简版.exe 2.2 安装Oracle的客户端 plsql工具 plsql_developer_green 3、使用plsql 使用指定用户名和密码打开工具 创建用户-新建-用户-输入账号密码users/temp/权限 切换登录的用户,重新登录就好了 表–找到tables-右键点新建-起个表名-加一些字段 记录–选中表名-右键编辑数据