包头

create or replace package pro_test as
TYPE out_cursor IS REF CURSOR;
procedure Alarm_ContentsByTime(
p_StartTime varchar2, ----开始时间
p_EndTime varchar2, ----结束时间
io_cursor in OUT out_cursor
); end pro_test;

包体

create or replace package body pro_test is

  procedure Alarm_ContentsByTime(
p_StartTime varchar2, ----开始时间
p_EndTime varchar2, ----结束时间
io_cursor in OUT out_cursor
) is
cursor cursor_1 IS
--获取 列用于循环。
select DISTINCT t.ps_productorcode code, t.PS_PRODUCTORNAME name,1 type FROM PSINFO_PRODUCTYIELD_SB t
union all
select DISTINCT f.ps_rawcode code,f.ps_rawname name,2 type from PSINFO_RAWMATERIALS_SB f
ORDER BY type,code;
V_SQL VARCHAR2(6000);
begin
V_SQL := 'select ''市本级'' as c0003_stname, 1 as c0003_stcode';
FOR V_XCLCK IN cursor_1
LOOP
V_SQL := V_SQL || ',' || 'min(case when t1.ps_name=''' || V_XCLCK.name ||
''' then t1.ps_name end) as ' || V_XCLCK.name||'mc'|| ',' || 'min(case when t1.ps_name=''' || V_XCLCK.name ||
''' then t1.cl end) as ' || V_XCLCK.name||'cl'|| ',' || 'min(case when t1.ps_name=''' || V_XCLCK.name ||
''' then t1.ps_unit end) as ' || V_XCLCK.name||'dw';
END LOOP;
V_SQL := V_SQL || ' from t0003_station t
inner join (
select
c.c0003_stcode,
c.c0003_stname,
a.ps_productorname ps_name,
a.ps_unit,
sum(nvl(a.ps_productoryield,0)) cl
from t0003_station c,PSINFO_PRODUCTYIELD_SB a
where a.c0003_stcode=c.c0003_stcode
and a.ps_month>=to_date('''||p_StartTime||''',''yyyy-mm-dd hh24:mi:ss'')
and a.ps_month<=to_date('''||p_EndTime||''',''yyyy-mm-dd hh24:mi:ss'')
group by c.c0003_stcode,c.c0003_stname,a.ps_productorname,a.ps_unit
union all
select
c.c0003_stcode,
c.c0003_stname,
b.ps_rawname ps_name,
b.ps_unit,
sum(nvl(b.ps_productoryield,0)) cl
from t0003_station c,PSINFO_RAWMATERIALS_SB b
where b.c0003_stcode=c.c0003_stcode
and b.ps_month>=to_date('''||p_StartTime||''',''yyyy-mm-dd hh24:mi:ss'')
and b.ps_month<=to_date('''||p_EndTime||''',''yyyy-mm-dd hh24:mi:ss'')
group by c.c0003_stcode,c.c0003_stname,b.ps_rawname,b.ps_unit
) t1 on t.c0003_stcode=t1.c0003_stcode
left join t0070_enterprise t70 on
t.c0003_stcode=t70.c0003_stcode
and t70.c0003_year=t1.c0003_stcode
and t70.c0070_stcode_ctrl=''320100''
group by t.c0003_stname,t.c0003_stcode ';
DBMS_OUTPUT.PUT_LINE(V_SQL);
--V_SQL := 'CREATE OR REPLACE VIEW RESULT AS '|| V_SQL;
open io_cursor for V_SQL;
end Alarm_ContentsByTime;
end pro_test;

执行之后

链接地址:http://www.cnblogs.com/blue123/p/8441112.html


oracle 存储过程-动态行转列,解决。的更多相关文章

  1. 中等难度SQL语句(存储过程,分页,拼接字段、游标,日期类型转换,动态行转列,视图)汇总

    一.创建存储过程 if Exists(select name from sysobjects where NAME = 'sp1LoginUser' and type='P')drop procedu ...

  2. 【转】MySQL存储过程中使用动态行转列

    MySQL存储过程中使用动态行转列 最近做项目关于数据报表处理,然而数据库存储格式和报表展现形式不同,需要进行一下行转列的操作,在做上一个项目的时候也看了一下,但是后来换了读取方式,也就没深入研究这个 ...

  3. MySQL存储过程的动态行转列

    MySQL存储过程中使用动态行转列 最近做项目关于数据报表处理,然而数据库存储格式和报表展现形式不同,需要进行一下行转列的操作,在做上一个项目的时候也看了一下,但是后来换了读取方式,也就没深入研究这个 ...

  4. [MSSQL]採用pivot函数实现动态行转列

    环境要求:2005+ 在日常需求中常常会有行转列的事情需求处理.假设不是动态的行,那么我们能够採取case when 罗列处理. 在sql 2005曾经处理动态行或列的时候,通常採用拼接字符串的方法处 ...

  5. MySQL 行转列 -》动态行转列 -》动态行转列带计算

    Pivot Table Using MySQL - A Complete Guide | WebDevZoomhttp://webdevzoom.com/pivot-table-using-mysql ...

  6. 在论坛中出现的比较难的sql问题:39(动态行转列 动态日期列问题)

    原文:在论坛中出现的比较难的sql问题:39(动态行转列 动态日期列问题) 最近,在论坛中,遇到了不少比较难的sql问题,虽然自己都能解决,但发现过几天后,就记不起来了,也忘记解决的方法了. 所以,觉 ...

  7. Oracle存储过程动态创建临时表/存储过程执行权限问题--AUTHID CURRENT_USER

    关于Oracle存储过程执行权限问题的解决 http://blog.sina.com.cn/s/blog_6ceed3280101hvlo.html (2014-04-02 04:06:28) 转载▼ ...

  8. mybatis 动态行转列

    SELECT user_name , MAX(CASE course WHEN '数学' THEN score END ) 数学, MAX(CASE course WHEN '语文' THEN sco ...

  9. 在论坛中出现的比较难的sql问题:42(动态行转列 考勤时间动态列)

    原文:在论坛中出现的比较难的sql问题:42(动态行转列 考勤时间动态列) 所以,觉得有必要记录下来,这样以后再次碰到这类问题,也能从中获取解答的思路.

  10. 在论坛中出现的比较难的sql问题:37(动态行转列 某一行数据转为列名)

    原文:在论坛中出现的比较难的sql问题:37(动态行转列 某一行数据转为列名) 所以,觉得有必要记录下来,这样以后再次碰到这类问题,也能从中获取解答的思路.

随机推荐

  1. kubeSphere+kubernetes 集群更新证书

    模拟问题点 使用kubernetes时错误提示 yang@master:~$ kubectl get nodes Unable to connect to the server: x509: cert ...

  2. python中下拉框选择

    如选择省区城市 provice = driver.find_element_by_id('****') #先给定位的元素付个变量 select(prvice).select_by_bisible_te ...

  3. 关于Python 面向对象寻值的问题. How the number be found in the OOP in Python

    今天在看Python面向对象的时候看到了一个很有意思的问题 Today. When i learning the OOP in python , I found a very interesting ...

  4. 利用XtraBackup实现PXC数据库的热备份

    PXC 容器中安装XtraBackup apt-get updata 1.在宿主机创建数据库卷,将数据卷映射到某个数据库的节点上 docker volume create backup 2.暂停nod ...

  5. 25js String(字符串)对象

    <!DOCTYPE html> <html lang="en">   <head>     <meta charset="UTF ...

  6. uniapp离线打包安卓未配置appkey或配置错误

    按照这4步检查都没问题 1.查看签名文件是否配置到了主APP的build.gradle. signingConfigs { config { keyAlias 'newPt' keyPassword ...

  7. 【ubuntu20】解压文件

    第一类处理 *** .zip或 ***.rar 时,需要先下载相对应的unzip和unrar,可在终端,执行 sudo apt-get install unzipsudo apt-get instal ...

  8. 2.4G收发一体芯片NRF24L01P跟国产软硬件兼容 SI24R1对比

    超低功耗高性能 2.4GHz GFSK 无线收发器芯片Si24R1Si24R1 是一颗工作在 2.4GHz ISM 频段,专为低功耗无线场合设计,集成嵌入式ARQ 基带协议引擎的无线收发器芯片.工作频 ...

  9. 在wsl 2中编译自己的魔趣(mokee) ROM

    1.安装wsl2 a.在windows 10 系统中启用wsl2(只能是wsl2,wsl1 会编译失败), 并商店中下载ubuntu镜像,商店默认安装位置为C:\Program Files\Windo ...

  10. 读后笔记 -- Java核心技术(第11版 卷 II) Chapter5 数据库编程

    5.1 JDBC API 1. JDBC (Java Database Connectivity) is an API for interacting with a database in Java. ...