Oracle动态SQL语句
动态SQL返回游标:
create or replace procedure proc_ValidityDueQuery(
p_regioncode in number,
p_pscode in number,
p_outputcode in number,
p_pollutantType in number,
p_psclasscode in varchar2,
p_attencode in varchar2,
p_checkstatus in number,
p_auditstatus in number,
p_cursor out curdata
)
as
begin
open p_cursor for
'select bs.regioncode,
bs.regionname,
bs.pscode,
bs.psname,
bs.outputcode,
bs.outputname,
bs.ptype,
bd.chkname,
bd.approvename,
bd.pollutantname,
case when ((bd.maxvalidtill - sysdate) > 0 and (bd.maxvalidtill - sysdate) <= 7) then ''yellow''
when (sysdate - bd.maxvalidtill) > 0 then ''red''
end color,
case when bs.ptype = 1 then ''水'' when bs.ptype = 2 then ''气'' end pstype,
bd.auddate,
to_char(bd.maxvalidtill, ''yyyy-MM-dd HH24:mi'') validtill
from (select vb.regioncode,
vb.regionname,
vb.pscode,
vb.psname,
vo.outputcode,
vo.outputname,
vo.ptype
from (select oregioncode regioncode, oregionname regionname, pscode, psname
from v_baseinfo
where 1 = 1
'|| case when p_regioncode >0 then 'and oregioncode='|| p_regioncode else '' end ||'
'|| case when p_pscode>0 then 'and pscode='|| p_pscode else '' end ||'
'|| case when p_psclasscode<>'0' then 'and psclasscodexc in ('|| p_psclasscode ||')' else '' end ||'
'|| case when p_attencode<>'0' then 'and attentiondegreecode in ('|| p_attencode ||')' else '' end ||'
) vb,
(select pscode, outputcode, outputname, inout, psstatus, ptstatus, ptype
from v_output t
where psstatus = 0
and ismonitor = 1
and ptstatus = 0
'|| case when p_pscode>0 then 'and pscode='|| p_pscode else '' end ||'
'|| case when p_outputcode>0 then 'and outputcode='|| p_outputcode else '' end ||'
'|| case when p_checkstatus=1 then 'and isgjkh=1 or isskkh=1'
when p_checkstatus=0 then 'and isgjkh=0 or isskkh=0'
else ''
end || '
and ptype ='|| p_pollutantType ||'
'|| case when p_psclasscode<>'0' then 'and psclasscodexc in ('|| p_psclasscode ||')' else '' end ||'
'|| case when p_attencode<>'0' then 'and attentiondegreecode in ('|| p_attencode ||')' else '' end ||'
) vo
where vb.pscode = vo.pscode) bs,
(select pscode, outputcode, pollutantname, pollutantcode,
auddate,maxvalidtill, approvename, chkname
from v_scenecommonite
where checkresult=''1''
'|| case when p_pscode>0 then 'and pscode='|| p_pscode else '' end ||'
'|| case when p_outputcode>0 then 'and outputcode='|| p_outputcode else '' end ||'
'|| case when p_auditstatus=1 then 'and ((maxvalidtill - sysdate) > 0 and (maxvalidtill - sysdate) <= 7)'
when p_auditstatus=2 then 'and maxvalidtill >= sysdate-90'
when p_auditstatus=3 then 'and sysdate>maxvalidtill'
else ''
end ||'
) bd
Where bs.pscode=bd.pscode
and bs.outputcode=bd.outputcode
order by bd.maxvalidtill desc, bs.regioncode, bs.pscode, bs.outputcode';
end proc_ValidityDueQuery;
2.动态创建暂时表
--创建暂时表
--推断是否存在
select count(*)
into v_num
from user_tables
where table_name=upper('zstemptable');
--假设不存在则创建
if v_num=0 then
execute immediate 'create global temporary table zstemptable(id number(1),reviseddata number(20,6))
on commit preserve rows';
end if;
--插入数据
execute immediate 'insert into zstemptable
select 1,RevisedStrength
from (select RevisedStrength
from t_mod_gasfachourdata
where pscode = '|| p_pscode ||'
and outputcode = '|| p_outputcode ||'
and pollutantCode = '''|| p_pollutantcode ||'''
and monitorTime < to_date('''|| p_recordTime ||''',''yyyy-MM-dd HH24:mi:ss'')
and availableStatus = 0
order by MonitorTime desc)
where rownum = 1';
--查询数据
execute immediate 'select count(*) from zstemptable where id=1' into v_hisstrength;
--清除表信息
execute immediate 'truncate table zstemptable';
Oracle动态SQL语句的更多相关文章
- oracle 存储过程 动态sql语句
一.在oracle项目开发中越到问题: 在利用ODP向oracle中插入数据时,如果这样写: insert into clobTable (id, story) values(1,'....'); ...
- 使用Oracle的DBMS_SQL包执行动态SQL语句
引用自:http://blog.csdn.net/ggjjzhzz/archive/2005/10/17/507880.aspx 在某些场合下,存储过程或触发器里的SQL语句需要动态生成.Oracle ...
- Oracle基础 动态SQL语句
一.静态SQL和动态SQL的概念. 1.静态SQL 静态SQL是我们常用的使用SQL语句的方式,就是编写PL/SQL时,SQL语句已经编写好了.因为静态SQL是在编写程序时就确定了,我们只能使用SQL ...
- MyBatis学习(三)、动态SQL语句
三.动态SQL语句 有些时候,sql语句where条件中,需要一些安全判断,例如按某一条件查询时如果传入的参数是空,此时查询出的结果很可能是空的,也许我们需要参数为空时,是查出全部的信息.使用Orac ...
- Oracle动态执行语句
一.为什么要使用动态执行语句? 由于在PL/SQL 块或者存储过程中只支持DML语句及控制流语句,并不支持DDL语句,所以Oracle动态执行语句便应允而生了.关于DDL与DML的区别,请参见:D ...
- 三、动态SQL语句
//备注:该博客引自:http://limingnihao.iteye.com/blog/106076 有些时候,sql语句where条件中,需要一些安全判断,例如按某一条件查询时如果传入的参数是空, ...
- MyBatis学习 之 三、动态SQL语句
目录(?)[-] 三动态SQL语句 selectKey 标签 if标签 if where 的条件判断 if set 的更新语句 if trim代替whereset标签 trim代替set choose ...
- Oracle和SQL语句的优化策略(基础篇)
转载自: http://blog.csdn.net/houpengfei111/article/details/9245337 http://blog.csdn.net/uniqed/article/ ...
- Oracle 动态sql 实现方式
/******************************************************************* Sample Program 10: Dynamic SQL ...
随机推荐
- Spring MVC 转发和重定向
本文介绍Spring MVC中转发和重定向的区别. 转发和重定向 开始Java EE时,可能会对转发(forward)和重定向(redirect)这个两个概念不清楚.本文先通过代码实例和运行结果图片感 ...
- 各消息队列对比,Kafka深度解析,众人推荐,精彩好文!
http://blog.csdn.net/allthesametome/article/details/47362451
- ZOJ Problem Set - 3822Domination(DP)
ZOJ Problem Set - 3822Domination(DP) problemCode=3822">题目链接 题目大意: 给你一个n * m的棋盘,每天都在棋盘上面放一颗棋子 ...
- C# 之 继承
继承 继承是OOP最重要的特性之中的一个.不论什么类都能够从还有一个类中继承,这就是说,这个类拥有它继承的类的全部成员. 在OOP中,被继承的类称为父类. 在C#中的对象仅能直接派生于一个基类 ...
- msp430在ccsv5下出现的问题总结
一.内存问题 问题描写叙述,报错: program will not fit into available memory. placement with alignment fails for se ...
- es67
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Android图像处理之熔铸特效
代码: package com.color; import android.content.Context; import android.graphics.Bitmap; import androi ...
- css中linear-gradient的使用
注明:此篇文章来自http://www.cnblogs.com/lhb25/archive/2013/01/30/css3-text-shadow.html.
- POJ 2133 暴搜
题意: 思路: 按照题意暴搜 注意 如果目标串==给的串 答案是2 //By SiriurRen #include <cstdio> #include <cstring> #i ...
- AC自动机 hdu2222
#include <iostream> using namespace std; struct Node{ Node *next[]; Node* fail; int count; Nod ...