sql相关记录

mysql中可以使用

show table status from myssh

来显示数据库下每个表的详细信息,如Rows表拥有的记录数

 

oracle中若要显示每个表的占有内存的大小,可以使用

select SEGMENT_NAME,TABLESPACE_NAME,sum(BYTES/1024/1024)||'M' m from dba_extents where SEGMENT_TYPE='TABLE'
group by SEGMENT_NAME,TABLESPACE_NAME ORDER BY m DESC

相关赋权语句

 

grant select on dba_extents to ***;

 

LENGTH(),中文算两个长度

 

SELECT LENGTH(TRIM(u.email)) FROM users u where id=3

REGEXP_INSTR()

 

 

SELECT REGEXP_INSTR('.3.542.','\d',1,2) FROM DUAL;

 


regexp_instr的原型如下: 
regexp_instr(x,pattern[,start[,occurrence[,return_option[,match_option]]]]) 
这里每个参数分别含义如下: 
x 待匹配的字符串 
pattern 待匹配的模式 
start   开始匹配的位置,如果不指定默认为1 
occurrence 匹配的次数,如果不指定,默认为1 
return_option 指定返回值的类型,如果该参数为0,则返回值为匹配位置的第一个字符,如果该值为非0则返回匹配值的最后一个位置。 
match_option 可以用这个参数来修改一些默认的配置设置。这个值与前面所说的regexp_like函数中的match_option参数的意义是一样的。 

INSTR()

 

SELECT INSTR('.3.542.','.5') FROM DUAL;

 

INSTR返回的是一个字符串在另外一个字符串中的位置,index从1开始,如没有则返回0,一样支持 开始匹配的位置和匹配的次数参数

SUBSTR()

 

SELECT SUBSTR('hello world',2,2) FROM DUAL;//从index=2开始截取2个字符


REPLACE()

 

 

SELECT REPLACE('JACK and JUE','J','BL') FROM DUAL;


REGEXP_REPLACE()

 

 

SELECT REGEXP_REPLACE('500   Oracle       Parkway,    Redwood   Shores, CA', '( ){2,}',' ') FROM DUAL;

 

to_date()

 

select to_date(sysdate,'yyyy-mm-dd hh:mi:ss') from dual;


to_char()

 

 

select to_char(sysdate,'yyyy-mm-dd hh:mi:ss') from dual;


js中可以这样通过函数来计算前后时间

 

 

var endTime = new Date(new Date().getTime() + 86400000*3).dateFormat("Y-m-d H:mm:ss");

--Oracle trunc()函数的用法
/**************日期********************/
1.select trunc(sysdate) from dual  今天的日期
2.select trunc(sysdate, 'mm') from dual  返回当月第一天.
3.select trunc(sysdate,'yy') from dual  返回当年第一天
4.select trunc(sysdate,'dd') from dual  返回当前年月日
5.select trunc(sysdate,'yyyy') from dual  返回当年第一天
6.select trunc(sysdate,'d') from dual  (星期天)返回当前星期的第一天
7.select trunc(sysdate, 'hh') from dual 2016-10-10 17:00:00 当前时间为17:35 
8.select trunc(sysdate, 'mi') from dual 2016-10-10 17:35:00 TRUNC()函数没有秒的精确
/***************数字********************/
/*
TRUNC(number,num_digits) 
Number 需要截尾取整的数字。 
Num_digits 用于指定取整精度的数字。Num_digits 的默认值为 0。
TRUNC()函数截取时不进行四舍五入
*/
9.select trunc(123.458) from dual --123
10.select trunc(123.458,0) from dual --123
11.select trunc(123.458,1) from dual --123.4
12.select trunc(123.458,-1) from dual --120
13.select trunc(123.458,-4) from dual --0
14.select trunc(123.458,4) from dual --123.458
15.select trunc(123) from dual --123
16.select trunc(123,1) from dual --123
17.select trunc(123,-1) from dual --120
mysql慢查询相关,修改my.ini配置文件来启动慢查询

 

//查看慢查询时间
show variables like "long_query_time";默认10s
//查看慢查询配置情况
show status like "%slow_queries%";
//查看慢查询日志路径
 show variables like "%slow%";
 注意:这些日文件在mysql重启的时候才会生成
#记录所有sql语句
log=E:/mysqllog/mysql.log
#记录数据库启动关闭信息,以及运行过程中产生的错误信息
log-error=E:/mysqllog/myerror.log
# 记录除select语句之外的所有sql语句到日志中,可以用来恢复数据文件
log-bin=E:/mysqllog/bin
#记录查询慢的sql语句
log-slow-queries=E:/mysqllog/slow.log  
#慢查询时间
long_query_time=0.5

 

posted @ 2016-10-10 01:02  海的心  阅读(118)  评论(0编辑  收藏  举报