数据库资料

一、Oracle

1、将日期类型设置为自己想要的类型

eg:
to_char(hiredate,'YYYY-MM-DD HH24:MI:SS')
to_char(nvl(t.ANSTIME,'') ,'yyyy-MM-dd HH:MM:ss')   hfsj


2、将字符串类型转换成时间类型

to_date(hiredate,'yyyy-mm-dd hh24:mi:ss')这样放到数据库中就是date类型


二、Mysql

1、将字符串转换成时间类型

date_format(‘字符串’,'%Y-%m-%d') ;

将数值型 转换成字符串:CONCAT(t.id,'') id
将数值类型数据转换 小数点后保留两位 的字符串:TRUNCATE(t.remain_give_money / 100, 2) remain_give_money
将数值类型数据转换成字符串类型:FORMAT(t.give_money / 100, 2) give_money
2、新增字段
alter TABLE table_name ADD city_id INT COMMENT '城市信息 1:上海市 2:深圳市 3:杭州市'


一)
select  p1.pk_psndoc,p1.pk_machine 考勤机主键, p1.calendartime  打卡时间 
from tbm_importdata p1 
where 
p1.pk_psndoc='1003A41000000000030J'
and
p1.pk_importdata = (
select MIN(p2.calendartime) from tbm_importdata p2  
group by SUBSTRING(p2.calendartime,1,10)
)


select * from tbm_machineaddress
select * from tbm_importdata;


select tbm_machineaddress.machinecode from (
select p2.pk_machine, pk_psndoc, MIN(p2.calendartime) ctime from tbm_importdata p2  
where SUBSTRING(p2.calendartime,1,10) = '2014-03-10' --日期
and p2.pk_psndoc = '1003A41000000000030J' -- 人pk
group by SUBSTRING(p2.calendartime,1,10), p2.pk_machine, p2.pk_psndoc) temp1
left join tbm_machineaddress on tbm_machineaddress.pk_machine = temp1.pk_machine




select p1.pk_machine,p1.pk_psndoc,MIN(p1.calendartime) ctime from tbm_importdata p1,mct_cbgs p2
where SUBSTRING(p1.calendartime,1,10)= p2.ddate 
and p2.ddate='2013-03-04'
 
group by SUBSTRING(p1.calendartime,1,10),p1.pk_machine,p1.pk_psndoc


select * from mct_cbgs


select * from tbm_importdata;


update mct_cbgs set ddate='2014-03-03' where ddate='2014-03-03'




select  pk_machine 考勤机主键, calendartime  打卡时间 
from tbm_importdata where pk_psndoc='1003A41000000000030J'
and pk_importdata p1 in (
select pk_imp


-- 数据中字段截取
SELECT substr('This is a test', 6, 2) FROM dual 返回 is


二)


查询当前系统时间+90天后的日期(涉及到参照信息)
Vcustcode->getColValue(bd_cubasdoc,custcode ,pk_cubasdoc ,
getColValue(bd_cumandoc,pk_cubasdoc , pk_cumandoc, pk_cubasdoc));


select a.billcode 合同编号,c.custname 名称,a.enddate 结束日期 from 
shcdp_khcontract a
left join bd_cumandoc  b on a.pk_cubasdoc=b.pk_cumandoc 
left join bd_cubasdoc c on c.pk_cubasdoc=b.pk_cubasdoc
where a.enddate < CONVERT(varchar(10),GETDATE()+90,120)
and a.enddate is not null
and a.enddate > CONVERT(varchar(10),GETDATE(),120)




select getdate(); //当前系统时间


select 当前日期=convert(varchar(10),getdate()+90,120)  
,当前时间=convert(varchar(8),getdate(),114)



三)插入数据信息
 insert into my_emailpart 
  select substring(emailinfo_name,CHARINDEX('_',emailinfo_name)+1,99) from bd_emailinfo where emailinfo_name is not null and emailinfo_name <>''
  and emailinfo_name like '%@gcl.com%' and CHARINDEX('_',emailinfo_name) > 0;
  
  
  
四)MYSQL 数据库
1、关于时间格式问题处理
select IFNULL(max(create_date),STR_TO_DATE('2013-05-01 00:00:00','%y-%m-%d %T'))  lastdate from t_article ;
2、-- mysql数据库时间字段截取
select max(date_format(create_date ,'%Y-%m-%d' )) create_date  from t_article  

3、-- where条件时将字符串转换成时间格式
select t.ARTICLE_ID,t.title,t.BRIEF,IFNULL(t.CATALOG_ID,'0000') CATALOG_ID,t.type,b.CONTENT,
STR_TO_DATE(t.create_date,'%Y-%m-%d %T') AS create_date
from t_article t
left join t_article_content b 
on t.article_id = b.article_id
where t.create_date =  cast('2013-07-20 03:09:32' as datetime);



五、数据库中新增列字段
alter table l_insurence add (LICENSEPLATENO VARCHAR2(15));
comment on column l_insurence.LICENSEPLATENO is '车牌号';


六、修改字段列名属性
alter table t_fzw_notice_product modify OPEN_SHARE number(32,4)


七、杀掉数据库用户进程
1)查询该用户的进程
select sess.sid, 
sess.serial#, 
lo.oracle_username, 
lo.os_user_name, 
ao.object_name, 
lo.locked_mode 
from v$locked_object lo, 
dba_objects ao, 
v$session sess 
where ao.object_id = lo.object_id and lo.session_id = sess.sid; 
2) 杀掉!
alter system kill session '738,1429'; 


八、查询数据库共有多少表
select count(*) from tabs

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值