一 日期函数
1 获得系统日期 select sysdate from dual
2 日期d加n个月 add_months(d,n)
eg : select add_months(sysdate,5) from dual--->2009-6-12 9:21:53(2009-1-12执行)
3 获得n天后的日期
eg select sysdate+6 from dual (获得六天后的日期)
4 日期截断函数------trunc(d [,fmt])
1 )截断到月份 (即获得日期当月月份的一号的日期)--- trunc(d,'month')
eg: select trunc(to_date('05/25/1995','mm/dd/yyyy'),'month') from dual--->1995-5-1
2 )截断到年 (即获得日期当年的一月一号的日期) trunc(d,'year')
eg:select trunc(to_date('05/25/1995','mm/dd/yyyy'),'year') from dual-->1995-1-1
3)截断到日 trunc(d,'dd')
eg:
select trunc(to_date('05/10/1995 14:23:30','mm/dd/yyyy hh24:mi:ss'),'dd') from dual
--->1995-5-10
5 日期四舍五入函数---trunc(d [,fmt])
1)舍入到年trunc(d,'year')
(当月份为1-6的时候返回当年的一月一日,当月份为7-12(包含7的时候返回下一年的一月一日))
eg select round(to_date('2009-06-30','yyyy/mm/dd'),'year') from dual --->2008-1-1
select round(to_date('2008-07-01','yyyy/mm/dd'),'year') from dual-->2009-1-1
2 )舍入到月trunc(d,'month')
当号数为1-15(含15)时返回当月的一号,当号数为16-月底时返回下个月的一号(不论当月的天数,是否
为闰年都是如此)
select round(to_date('2009-10-15','yyyy/mm/dd'),'month') from dual-->2009-10-1
select round(to_date('2009-10-16','yyyy/mm/dd'),'month') from dual-->2009-11-1
6获得日期的年,月,日,时,分,秒
select to_char(sysdate,'yyyy') from dual
select to_char(sysdate,'mm') from dual
select to_char(sysdate,'dd') from dual
select to_char(sysdate,'hh24') from dual
select to_char(sysdate,'mi') from dual
select to_char(sysdate,'ss') from dual
如果要获得整数类型的数字则要附加转化
eg: select to_number(to_char(sysdate,'yyyy')) from dual
7 获得两个日期间的月份数
months_between(D1,D2)
用法: months_between(D1,D2)用d1-d2的月份值,返回小数形式
eg:select months_between(to_date('2009-03-20','yyyy/mm/dd'),to_date('2009-02-26','yyyy/mm/dd')) from dual
--->0.806451612903226
二 字符串函数
1 求长度函数 length(st)
select length('abc') from dual-->3
2 去空格函数
trim(st) 去掉左边和右边的空格
ltrim(st) 去掉左边的空格
rtrim(st) 去掉右边的空格
3 求子串函数
substr(st,m[,n]) n=返回st串的子串,从m位置开始,取n个字符长。缺省时,一直返回到st末端
4 左补,右补函数
左补:lpad(st1,n[,st2]) 返回右对齐的st,st为在st1的左边用st2填充直至长度为n,st2的缺省为空格
eg: select lpad('1234',8,'0') from dual-->00001234
右补函数:
rpad(st1,n[,st2]) 返回左对齐的st,st为在st1的右边用st2填充直至长度为n,st2的缺省为空格
eg:select rpad('5678',8,'9') from dual-->56789999
修改表的结构
alter table wo_ingateway_inf modify GATEWAYADDRESS VARCHAR2(30) null;
修改列名字
alter table test_qjk_stu1 rename column oldname to newname;
删除表结构
alter table wo_workorder drop column CONTENT;
重命名表
alter table wo_spInfo_bak rename to wo_spInfo_history;
添加列
alter table wo_workorder add content long null;
使约束失效(SYS_C0010800为约束的名字)
alter table wo_orderclaimant disable constraint SYS_C0010800;
删除约束('R'为外键约束类型)
delete from user_constraints uc where uc.TABLE_NAME LIKE 'WO_INGATEWAY_INF' and uc.constraint_type='R';
alter table wo_workorder DROP constraint SYS_C004752
查看约束
select * from user_constraints uc1 where uc1.constraint_name in(
select uc.r_constraint_name from user_constraints uc where uc.TABLE_NAME LIKE 'WO_ORDERCLAIMANT' and uc.constraint_type='R');
建表约束
create table test_qjk_city(
id int primary key,
name varchar2(50) unique,
nationid int,
constraints fk1 foreign key (nationid)
references test_qjk_country(id)
);
建立序列
create sequence wo_spinfo_seq
increment by 1
start with 1
maxvalue 999999999
cycle;
查看用户序列
select * from user_sequences
建立普通的B索引
create index on tableName(column);
建立普通索引并压缩
create index on tableName(column) compress;
建立位图索引
create bitmap index on tableName(column) ;
手动修改数据前使用语句(即在控制台中直接修改,而不用自己手写update语句)
select * from skywin_userrole for update nowait
exists的用法:
eg:查询没有选修大学物理的学生
select * from test_qjk_student stu
where not exists (select * from test_qjk_courseSelect cs where cs.sid=stu.sid
and exists (select * from test_qjk_course c where c.cname='大学物理' and c.cid=cs.cid)
)
授权
grant imp_full_database,imp_full_database to esbtest;(导入导出权限)