oracle基础话语
1. 插入语句
1.1 插入单行数据
insert into tablename (column1,column2,column3) values ('value1','value2','value3');
1.2 现有表抽取插入另一张表
insert into tablename (column1,column2,column3) select column1,column2,column3 from tablename2;
注: 查询得到的数据个数、顺序、数据类型等必须与插入的项保持一致
2. 删除语句
2.1 delete语句
delete from tablename where column1=value1;
delete from tablename;
注: 保留表结构,可回滚,速度慢,更新日志
2.2 truncate语句
truncate table tablename;
注: 保留表结构,不可回滚,速度中,所用日志空间较少
2.3 drop语句
drop table tablename;
注: 删除表,不可回滚,速度快
3. 更新语句
3.1 按条件更新
update tablename set column1=value1 where column1=value1;
4. 查询语句
4.1 order by
select * from tablename where column1=value1 order by column1;
4.2 常量
select tb.*,'上海' as address from tablename tb;
4.3 group by
select column1,sum(column2) from tablename where column3=value3 group by column1 having (column1=value1);
注: select后面的所有列中,没有使用聚合函数的列,必须出现在group by后面,having后面的参数必须在select后面或order by后面出现过
4.4 rownum
select tb.* from (select rownum num,t.* from tablename t where rownum <= 15) tb where num>10;
注: rownum重命名,不然where后rownum不能用大于
select * from (select * from tablename order by column1) where rownum <=15;
注: order by 后跟索引或主键,不需要子查询