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 ...
随机推荐
- javascript 基础篇 随课笔记
!DOCTYPE HTML><html><head><meta name="content-type" content="text/h ...
- 解决MyEclipse中安装或升级ADT之后SDK Target无法显示的问题
故障现象,在MyEclipse里面安装完最新的android sdk和ADT之后,无法新建项目,Build Target为空,显示一直在loading.即如下面图里面显示的,Target Na ...
- 小试VS 2017 开发Python Django项目过程一
一.新建项目python ->django web 项目 (选择带bootstrap风格与twwriter)项目名称iepiececomputing (ie计件计算)跳出窗体 -> 添加虚 ...
- python 爬虫使用
python爬虫架构 Python 爬虫架构主要由五个部分组成,分别是 调度器.URL管理器.网页下载器.网页解析器.应用程序. 调度器:相当于一台电脑的CPU,主要负责调度URL管理器.下载器.解析 ...
- 紫书 例题 9-14 UVa 1218 (树形dp)
这道题有个初始值设成1e9, 然后这个值是要加很多次的,然后就会溢出变成负数, 然后就一直WA, 找这个bug找了一个小时--以后不能随便这样设那么大, 要考虑会不会加很多次然后溢出. 讲一下思路. ...
- 【Henu ACM Round#14 C】Duff and Weight Lifting
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 2^y可以由两个2^(y-1)相加得到. 则有一个贪心的策略. 就是2^x尽量都变成2^(x+1) (即能够凑就尽量凑) 如果x还有 ...
- Linux学习总结(2)——linux常用命令大全
玩过Linux的人都会知道,Linux中的命令的确是非常多,但是玩过Linux的人也从来不会因为Linux的命令如此之多而烦恼,因为我们只需要掌握我们最常用的命令就可以了.当然你也可以在使用时去找一下 ...
- Chromium Graphics: Android L平台上WebView的变化及其对浏览器厂商的影响分析
原创文章.转载请以链接形式注明原始出处为http://blog.csdn.net/hongbomin/article/details/40799167. 摘要:Google近期公布的Android L ...
- 你如何理解 HTML5 的 section?会在什么场景使用?为什么这些场景使用 section 而不是 div?
section元素表示文档或应用的一个部分.所谓“部分”,这里是指按照主题分组的内容区域,通常会带有标题.[也就是每个section对应不同的主题.注意是内容本身的主题,而不是其他人为设定的划分标准. ...
- ajax处理响应(三)
一旦脚本调用了send方法,浏览器就会在后台发送请求到浏览器.因为请求是在后台处理的,所以Ajax依靠事件来通知你这个请求的进度的进展情况,在上个随笔的里,使用handleResponse函数 ...