sql总结

oracle
单表查询
select * from 表名;
select 字段名,... from 表名;
-- 去除重复行
select distinct 字段名,... from 表名;
-- as 起小名
select 字段名 as 小名 from 表名;
select 1+1 from dual;
select * from 表名 where 条件 and(or)
select * from 表名 where a> < = != <>
-- between and
select * from 表名 where 条件 between a and b
-- in
select * from 表名 where 条件 in(集合)
-- like 模糊查询 %代表所有,_代表一个
select * from 表名 where 条件 like % _
-- is not null
-- order by desc降序 asc 升序
select * from 表名 order by 字段名 降序(升序)
-- || 相当于java中的+
select 字段1||字段2 from 表名
-- rownum 行号
select rownum ,字段名 from 表名
-- 数字 字符 日期
abs sqrt ceil floor round trunc sign mod power
upper lower ltrim rtrim substr replace translate concat instr initcap length
months_between add_months next_day last_day round trunc
-- 转换函数
to_char to_date to_number
-- yyyy-mm-dd hh24:mi:ss
-- $999,999,999.99 L999,999,999.99
-- 常见的5种聚合函数
sum max min avg count
-- group by 分组函数
-- having 是分组后的条件
-- nvl 空转0 nvl2 升级版
-- decode() if else
-- case when then else end switch case
-- 插入语句
insert into 表名 values(全字段);
insert into 表名(字段名) values(对应的字段值);
--修改语句
update 表名 set 字段=new值 where 条件;
-- 删除语句
delete from 表名 where 条件;
-- 多表查询
表连接 和 子查询
92版99版
select * from A,B where a.*=b.* -- where 后确定两个表的关系
select * from A 关键字 join B on a.*=b.*
内连
inner join 取两边都合法的数据
外连
左外连 left join 以左表为主,右表对应
右外连 right join 以右表为主,左表对应
全外连 full join  左右表数据全部展示
交叉 cross join 笛卡尔积
自然 natural join 自然连
非等值连接
条件进行范围匹配
select * from A,B where A.*>b.* and A.*<b.*
union (去重复)将两个查询的结果以同一张表进行展示
必须是数据类型相同
union all (全部)
-- 子查询
把一个查询的结果做为另一个查询的条件
-- top n
select * from (select sal from emp order by sal desc)t
where rownum<=3;
-- 分页
select * from (select rownum r,t.* from (select sal from emp order by sal desc)t
where rownum<=5)
where r>=3;
-- 对象
database tablespace user table view index sequence function procedure trigger
create 对象名
alter or replace
drop
create sequence seq_表名
create table 表名(
       列名 数据类型 约束
)
int number float double integer
char varchar2 varchar
date timestamp
clob blob

主键 primary key 唯一 非空
唯一 unique
非空 not null
检查 check()
外键 foreign key  references
默认 default ''
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值