注意事项
- 1.数据类型 :
(1) 字符型 char 男女 varchar2
(2) 数字型 number
(3) 日期型 date timestamp(更加精确). - 2.建表必须加表空间
create 用户.table xxxxxxx tablespace
表空间 ams_data ams_idx
建表 必须要有主键,
必须有注释(表的注释,列的注释)comment on table tablename is ‘hehhehe’;
comment on column 用户名.表名.列名 is ‘1111’ - 3.建索引
create index xxxx on table(colum) tablespace - 4.添加列 不要在加列的给列赋默认值
- 5.约束
非空约束
唯一约束
检查约束
主键约束 = 非空约束 + 唯一约束 - 6.只有 insert update delete merge 需要 commit ,建表语句不需要
- 7.truncate 比 delete 相比,效率更高
- 8.列合并:|| select ename||’ job is ’||job from emp;
去除重复:distinct
select distinct job from emp;
排序:order by(默认升序,降序使用desc)
select ename,sal from emp order by sal; 从低到高排序
select ename,sal from emp order by sal desc; 从高到低排序 - 9.betwen 是闭区间
- 10 and 的优先级高于or
- 11
单行函数:
特点:对查询返回的每一行执行一次并返回一个值
根据处理的数据的类型差异,又分为:1) 字符串函数 2) 数字函数 3) 日期函数 4) 类型转换函数5) 通用函数 - 12.在语句中用函数,索引会失效‘
- 13.组函数自动忽略null值
- 14.group by分组函数:
1、如果在SELECT子句中包含了组函数,那么对于出现在SELECT子句中的单独的列,也必须同时包含在GROUP BY 子句中
2、在GROUP BY 子句中必须包含表中存在的列
3、在GROUP BY 子句中不能使用列别名
4、使用WHERE子句,可以在分组前排除一些行 - 15 不要使用笛卡尔积