1.获取无分隔符的32位UUID
uuid的生成采用的是postgresql的语法
select SYS_GUID_NAME() from dual;
2.查询慢查询
--查询执行中的语句
select *
from sys_stat_activity
Where state not like 'idle%';
--执行时间
select
current_timestamp - query_start as runtime,
datname,
usename,
pid,
query
from sys_stat_activity
where state != 'idle'order by 1 desc;
select
'select sys_terminate_backend('||pid||');'
from sys_stat_activity
where
state != 'idle'
AND query LIKE '%ELSE x.SQ* 100 / x.YQ%'
AND query NOT LIKE '%select pid from sys_stat_activity%';
--杀掉某个进程
select sys_terminate_backend(456258)
3. 时间戳与日期相互转换
3.1 时间格式改时间戳格式
SELECT to_number(extract('epoch' from now()::TIMESTAMP));
SELECT to_number(extract(epoch from timestamp '2014-01-28 01:10:01'));
3.2 时间戳格式改时间格式
SELECT TO_TIMESTAMP(1390871401)
4.根据当前日期获取本周一和周日
select trunc(sysdate,'W') - 7 from dual; --周一
select trunc(sysdate,'W') - 1 from dual; --周日
select trunc(sysdate,'Y') from dual; --本年1月1日 0时0分0秒
5.将表中的某个字段存储的多个值,以数据表的形式返回
select regexp_split_to_table('hello world', '\s+');
输出结果:
hello
world
table1.column1的值为675edb5b73394b75b94fb9ca7b45989e,3eff99c5b9cb49e7983f2171c2c8b71a,70cb7f8811ce49dc9cf30df98c0d50f1,d5b18df6bc194297b0a9260080386330
先想把此字符串以表的形式返回,如下操作即可:
SELECT regexp_split_to_table(column1, ',') from dual
输出结果为:
675edb5b73394b75b94fb9ca7b45989e
3eff99c5b9cb49e7983f2171c2c8b71a
70cb7f8811ce49dc9cf30df98c0d50f1
d5b18df6bc194297b0a9260080386330