Oracle操作笔记
1. 查询表记录中时间最新的数据
用括号单独查询最新大的时间 max(create_date) 再做表关联
select t1.workday,t.schedule_id,tss.name,t.*,t1.* from t_shifts t left join t_schedules tss on t.schedule_id = tss.id, (select workday, max(create_date) create_date from t_shifts where employee_id = 59214 and workday >= to_date('2019-01-01', 'yyyy-MM-dd') and workday <= to_date('2019-12-31', 'yyyy-MM-dd') group by workday) t1 where t1.workday = t.workday and t1.create_date = t.create_date and t.employee_id = 59214 and t.schedule_id not in (681, 717) order by t.workday;
2. exists替代in做查询
select * from t_physn_bind bin where exists (select info.system_customer_id from T_CUSTOMER_INFO info where info.user_id = 50267000 and info.system_customer_id = bin.system_customer_id)
3. varchar2和NVARCHAR2区别:
VARCHAR2最多存放4000字节的数据,最多可以可以存入4000个字母,或最多存入2000个汉字(数据库字符集编码是GBK时,varchar2最多能存放2000个汉字,数据库字符集编码是UTF-8时,那就最多只能存放1333个汉字,呵呵,以为最大2000个汉字的傻了吧!)
NVARCHAR2(size),size最大值为2000,单位是字符,而且不管是汉字还是字母,每个字符的长度都是2个字节。所以nvarchar2类型的数据最多能存放2000个汉字,也最多只能存放2000个字母。并且NVARCHAR2不受数据库字符集的影响。