参考 oracle11g行变列两种办法的比较:
方法1:优点是分析函数,缺点:返回log,低效,
select link_pid, replace(strs,',','|') all_forms
from
(select t.link_pid,
wmsys.wm_concat(t.form_of_way)
over(partition by t.link_pid order by t.form_of_way ) strs,
row_number() over(partition by t.link_pid order by t.form_of_way) RN,
count(1) over(partition by t.link_pid ) CNT
from rd_link_form t
) where RN=CNT
select t.link_pid,
listagg(t.form_of_way, '|')
within group (order by t.form_of_way ) all_forms
group by t.link_pid
【我以字典表user_tab_columns改写了上述SQL,如下,大家直接执行就行:】
方法1:
select table_name, replace(strs, ',', '|') all_forms
from (select t.table_name,
wmsys.wm_concat(t.COLUMN_NAME) over(partition by t.table_name order by t.COLUMN_NAME) strs,
row_number() over(partition by t.table_name order by t.COLUMN_NAME) RN,
count(1) over(partition by t.table_name) CNT
from user_tab_columns t)
where RN = CNT
select t.table_name,
listagg(t.COLUMN_NAME, '|')
within group (order by t.COLUMN_NAME ) all_forms
from user_tab_columns t
group by t.table_name
大家可以直接在自己的pl/sql中运行上述SQL
截取本周第一天:
SQL select sysdate,trunc(sysdate,'d') from dual;
SYSDATE TRUNC(SYSDATE,'D')
------------------- -------------------
当月数据
select * from table t
where t.create_time
=TRUNC(SYSDATE, 'MM')
and
t.create_time=last_day(SYSDATE) create_time为你要查询的时间
当年数据
=trunc(sysdate,'YYYY')
本周(国外周日为一个星期第一天)
where t.create_time =trunc(sysdate,'day')+1 and
--1、取某天在本周中的第几天(默认周日开始算第1天)
①.,
from dual;
以上就是土嘎嘎小编为大家整理的oracle如何查询一周相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!