Oracle数据库
/查询 表格字段信息 按住ctel 键 然后把鼠标放在表名上,左击/
– 单行注释
select* from student;
select * from student where rownum<=3; /柔ne mu /
显示前三行
显示四到六行
select * from student where rownum<=3 and id not in (select id from student where rownum<=3);
select * from student where id not in (select id from student where rownum<=3)and rownum<=3;
select rownum t ,id,name,sex,tel,home from student st ;
select * from (select rownum t ,id,name,sex,tel,home from student) m where m.t>=4 and m.t<=6;
–数据的增删改都需要一个commit;或者点一下提交commit按钮,如果删改过后没有提交可能会导致表锁,不能进行操作了
update student set age=‘40’ where id=‘12’;
commit;
insert into student(id,name,age) values(‘12’,‘高兴’,‘20’);
commit;
select *from student for update;对表进行更新
–对时间格式化Oracle
select * from scott.emp;
select to_char(hiredate,‘yyyy’)年份 from scott.emp;
select to_char(hiredate,‘MM’)月份 from scott.emp;
select to_char(hiredate,‘dd’)天 from scott.emp;
select to_char(hiredate,‘yyyyMMdd’)日期 from Scott。emp;
select *from 表名 where to_char(时间所在字段,‘yyyy’)=‘1981’;
select sysdate from dual;–查询系统时间
–dual是Oracle数据库里的一个虚拟表格 只有一行数据
select to_char(sysdate,‘yyyy_MM_dd’)from dual;
sql 替换字段中的部分字符,替换指定字符
把tal 表中lieming字段中2011的全部修改成2014,
如 lieming 里的201101131431改成201401131431,写法:update tab set lieming = replace(lieming,‘2011’,‘2014’);
1.取周的开始时间和结束时间:
开始时间(以星期一为开始时间):
select trunc(sysdate,‘D’)+1 from dual;
结束时间(以星期日为结束时间):
select trunc(sysdate,‘D’)+7 from dual;
2.取月的开始时间和结束时间:
月初时间:
select trunc(sysdate,‘MM’) from dual;
月末时间:
select last_day(sysdate) from dual;
3.取季的开始时间和结束时间:
季初时间:
select trunc(sysdate,‘Q’) from dual;
季末时间:
select add_months(trunc(sysdate,‘Q’),3)-1 from dual;
4.取年的开始时间和结束时间:
年初时间:
select trunc(sysdate,‘yyyy’) from dual;
年末时间:
select add_months(trunc(sysdate,‘yyyy’),12)-1 from dual;