您的位置:首页 > 数据库 > Oracle

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 mysql CRUD