Oracle 中用到的几个SQL语句

Oracle:

(1)时间到秒的写法:

 

INSERT INTO t_log(log_id,user_id,enter_time,log_off_time,description) 
VALUES(Log.NEXTVAL,?,to_date(?,'YYYY-MM-DD HH24:MI:SS


'),to_date(?,'YYYY-MM-DD HH24:MI:SS'),?)

 (2)将String类型的时间插入数据为Date类型用to_date函数的语句:

INSERT INTO t_soldoutgoods(so_id,so_starttime,so_endtime,goods_id,so_count,so_remark)
VALUES(SOLDOUTGOODS.NEXTVAL,TO_DATE(?,'YYYY-MM-DD')


,TO_DATE(?,'YYYY-MM-DD'),?,?,?)"

   从Date型取出来变为String型用to_char函数:

SELECT DISTINCT TO_CHAR(so_starttime,'YYYY-MM-DD'


)AS so_starttime,
TO_CHAR(so_endtime,'YYYY-MM-DD')AS so_endtime,so_count,so_remark FROM t_soldoutgoods 
ORDER BY so_starttime DESC 

 (3)decode函数:

select AD_CODE,AD_PIC,decode(AD_PIC_NUM,1,'首页',2,'朋友网络',3,'朋友群',4,'活动吧',5,'好去处')location


,
to_char(AD_DATE,'YYYY-MM-DD') ad_date,decode(STATUS,0,'无效',1,'有效') g,AD_CREATER 
from T_W_AD_INFO  order by to_date(ad_date,'YYYY-MM-DD') 
 

(4)日期的模糊查询:

SELECT l.log_id,p.person_name,.... FROM t_log l,t_user u,t_person p WHERE l.user_id = u.id AND 
u.personid = p.id AND to_char(l.enter_time,'yyyy-MM-dd HH:mm:ss') LIKE '%"+logBean.getEnter_time()
+"%'

 AND p.name LIKE '%"+logBean.getPerson_name()+"%'"
 

 

你可能感兴趣的:(oracle,sql,活动)