包头

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


最新文章

  1. 【iOS10 SpeechRecognition】语音识别 现说现译的最佳实践
  2. 解决OS X系统连接VPN后无法访问内网资源的问题
  3. HDU 3342 Legal or Not(判断是否存在环)
  4. js封装包
  5. iOS.Performance-trick-presentViewController-is-so-slow-in-didSelectRowAtIndexPath
  6. C语言中的指针和内存泄漏
  7. ZigZag Conversion [LeetCode]
  8. Digest [information value filtering]
  9. Android--获取使用的总流量和每个App的上传、下载的流量
  10. java 保留小数点后N位数(若干位),几种实现的方式总结
  11. chrome播放语音时,在chrome 控制台中报 DOMException: The play() request was interrupted by a call to pause(). 的问题.
  12. cross-document message 跨文档通信 HTML5
  13. 53-java中的queue
  14. Python3 tkinter基础 Menubutton 点击按钮出现下拉菜单
  15. tensorflow中命名空间、变量命名的问题
  16. Python设计模式 - 创建型 - 单例模式(Singleton) - 十种
  17. html5 canvas显示文字(写上5个字,纪念我那刚刚逝去的爱情)
  18. HDU1560 DNA sequence(IDA*)题解
  19. Kotlin语言学习笔记(5)
  20. iOS 直播推流 - 搭建基于RTMP的本地Nginx服务器

热门文章

  1. Jsonhelper类
  2. Nginx日志切割工具logrorate
  3. Docker Mysql修改时区
  4. sys&amp;faker&amp;jsonpath模块、异常处理、多线程、多进程
  5. Maven简答题
  6. WPF检测设备变化
  7. Android 杂项
  8. 日常遇到bug小记
  9. excel、word、PPT中插入PDF文件不显示图标问题
  10. potoshop制作一寸照片