Oracle和MySQL数据库操作语句笔记整理【持续更新】
2017-02-13 09:55
507 查看
主键:(oracle一般用序列,mysql一般用自动增长类型auto increment)
--oracle建序列(两个伪列:currval、nextval)
CREATE SEQUENCE SEQ_TMP
INCREMENT BY 1 -- 每次加几个
START WITH 1 -- 从1开始计数
NOMAXVALUE -- 不设置最大值 (MAXVALUE 99999999)
NOCYCLE -- 一直累加,不循环
CACHE 10; --设置缓存CACHE个序列,如果系统DOWN掉了或者其它情况将会导致序列不连续,也可以设置为NOCACHE
--mysql建序列(先设置主键,然后设置自动增长类型)
alter table temp_huawangxin add primary key(id);
alter table temp_huawangxin modify id int(100) not null auto_increment ;
--删除
Alter table temp_huawangxin change id id int(10);//删除自增长
Alter table temp_huawangxin drop primary key;//删除主建
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
翻页机制:(oracle比较繁琐,用ROWNUM,mysql用limit)
--分页查询,每页输出20条
--oracle
select * from (
select A.*,ROWNUM rn
from (select * from t temp_huawangxin) A
where ROWNUM<=40
)
where rn>=21;
--mysql
--其中start是页码,limit是每页显示的条数
select * fromtemp_huawangxinlimit
(start-1)*limit,limit;
-------------------------------------------------------------------------------------------------------
索引:
--oracle
非唯一性索引
create index index_a on table_a(id);
-------------------------------------------------------------------------------------------------------
模糊查询:
--oracle
两种,第二种适用于name字段为索引时更高效
select * from tb where name like '%XX%';
select * from tb where instr(name,'XX')>0;
--instr(title,'测试')>0 相当于 title like '%测试%'
--instr(title,'测试')=1 相当于 title like '测试%'
--instr(title,'测试')=0 相当于 title not like '%测试%'
未完待续。。。。。。
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--oracle建序列(两个伪列:currval、nextval)
CREATE SEQUENCE SEQ_TMP
INCREMENT BY 1 -- 每次加几个
START WITH 1 -- 从1开始计数
NOMAXVALUE -- 不设置最大值 (MAXVALUE 99999999)
NOCYCLE -- 一直累加,不循环
CACHE 10; --设置缓存CACHE个序列,如果系统DOWN掉了或者其它情况将会导致序列不连续,也可以设置为NOCACHE
--mysql建序列(先设置主键,然后设置自动增长类型)
alter table temp_huawangxin add primary key(id);
alter table temp_huawangxin modify id int(100) not null auto_increment ;
--删除
Alter table temp_huawangxin change id id int(10);//删除自增长
Alter table temp_huawangxin drop primary key;//删除主建
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
翻页机制:(oracle比较繁琐,用ROWNUM,mysql用limit)
--分页查询,每页输出20条
--oracle
select * from (
select A.*,ROWNUM rn
from (select * from t temp_huawangxin) A
where ROWNUM<=40
)
where rn>=21;
--mysql
--其中start是页码,limit是每页显示的条数
select * fromtemp_huawangxinlimit
(start-1)*limit,limit;
-------------------------------------------------------------------------------------------------------
索引:
--oracle
非唯一性索引
create index index_a on table_a(id);
-------------------------------------------------------------------------------------------------------
模糊查询:
--oracle
两种,第二种适用于name字段为索引时更高效
select * from tb where name like '%XX%';
select * from tb where instr(name,'XX')>0;
--instr(title,'测试')>0 相当于 title like '%测试%'
--instr(title,'测试')=1 相当于 title like '测试%'
--instr(title,'测试')=0 相当于 title not like '%测试%'
未完待续。。。。。。
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
相关文章推荐
- Oracle更新操作笔记以及语句
- oracle 数据操作语句(持续更新中...)
- oracle笔记整理8——生产批量操作语句、oracle系统包、创建用户并授权、变量属性
- 数据库-oracle常用SQL语句整理(持续更新中)
- oracle DBA常用操作语句 持续更新。。。
- Oracle SQL开发笔记(持续更新中...)
- oracle学习 六 删除表空间,数据文件的语句以及导入导出dmp文件的方法(持续更新中)
- linux管理操作个人笔记,持续更新!!!
- Oracle学习查询操作的笔记以及语句
- 在MySQL中实现插入或更新操作(类似Oracle的merge语句)
- 【PHP+MySQL学习笔记】php操作MySQL数据库中语句
- oracle 常用语句(持续更新)
- Oracle日常操作小常识(持续更新)
- oracle笔记整理16——表空间利用率、锁表、锁包、dbms_job操作
- MySQL中实现插入或更新操作(类似Oracle的merge语句)
- Oracle运维操作集锦[持续更新]
- Oracle常用语句集合-持续更新...
- CCNA 笔记整理之IP路由(持续更新)
- ABAP report常用的一些语句用法(包括字符串操作,变量动态操作)(持续更新)
- MySQL数据库操作个人备忘(持续更新)