动态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语句的更多相关文章

  1. oracle 存储过程 动态sql语句

    一.在oracle项目开发中越到问题: 在利用ODP向oracle中插入数据时,如果这样写:   insert into clobTable (id, story) values(1,'....'); ...

  2. 使用Oracle的DBMS_SQL包执行动态SQL语句

    引用自:http://blog.csdn.net/ggjjzhzz/archive/2005/10/17/507880.aspx 在某些场合下,存储过程或触发器里的SQL语句需要动态生成.Oracle ...

  3. Oracle基础 动态SQL语句

    一.静态SQL和动态SQL的概念. 1.静态SQL 静态SQL是我们常用的使用SQL语句的方式,就是编写PL/SQL时,SQL语句已经编写好了.因为静态SQL是在编写程序时就确定了,我们只能使用SQL ...

  4. MyBatis学习(三)、动态SQL语句

    三.动态SQL语句 有些时候,sql语句where条件中,需要一些安全判断,例如按某一条件查询时如果传入的参数是空,此时查询出的结果很可能是空的,也许我们需要参数为空时,是查出全部的信息.使用Orac ...

  5. Oracle动态执行语句

      一.为什么要使用动态执行语句? 由于在PL/SQL 块或者存储过程中只支持DML语句及控制流语句,并不支持DDL语句,所以Oracle动态执行语句便应允而生了.关于DDL与DML的区别,请参见:D ...

  6. 三、动态SQL语句

    //备注:该博客引自:http://limingnihao.iteye.com/blog/106076 有些时候,sql语句where条件中,需要一些安全判断,例如按某一条件查询时如果传入的参数是空, ...

  7. MyBatis学习 之 三、动态SQL语句

    目录(?)[-] 三动态SQL语句 selectKey 标签 if标签 if where 的条件判断 if set 的更新语句 if trim代替whereset标签 trim代替set choose ...

  8. Oracle和SQL语句的优化策略(基础篇)

    转载自: http://blog.csdn.net/houpengfei111/article/details/9245337 http://blog.csdn.net/uniqed/article/ ...

  9. Oracle 动态sql 实现方式

    /******************************************************************* Sample Program 10: Dynamic SQL ...

随机推荐

  1. LRJ入门经典-0906最短公共父串305

    原题 LRJ入门经典-0906最短公共父串305 难度级别:B: 运行时间限制:1000ms: 运行空间限制:256000KB: 代码长度限制:2000000B 试题描述 给定字符串A和字符串B,要求 ...

  2. GPU和CPU的区别

    http://blog.csdn.net/conowen/article/details/7256260 这里有几种计算平台的Flynn分类法 GPU是SIMD 多核CPU是MIMD 硬件结果多核处理 ...

  3. [Python] Understand List Comprehensions in Python

    List comprehensions provide a concise way to create new lists, where each item is the result of an o ...

  4. AVEVA RVM to 3D PDF

    AVEVA RVM to 3D PDF eryar@163.com RvmTranslator 3D PDF plugin can convert PDMS RVM files to 3D PDF w ...

  5. mybatis自己主动生成mapper,dao,映射文件

    一.先创建数据脚本,这里用的mysql数据脚本 drop table VOTE_ITEM; drop table VOTE_OPTION; drop table VOTE_SUBJECT; drop ...

  6. Server.MapPath()的用法

    http://blog.csdn.net/qiuhaifeng_csu/article/details/19416407 Server.MapPath(string path)作用是返回与Web服务器 ...

  7. 小程序block总结

    小程序block总结 1.block并不是一个组件,它仅仅是一个包装元素,不会在页面中做任何渲染,只接受控制属性. 2.因为 wx:if 是一个控制属性,需要将它添加到一个标签上.如果要一次性判断多个 ...

  8. 洛谷 P1911 L国的战斗之排兵布阵

    P1911 L国的战斗之排兵布阵 题目背景 L国即将与I国发动战争!! 题目描述 L国的指挥官想让他的每一个军营都呈现出国徽形——“L”形(方向无所谓).当然,他的指挥营除外(这叫做个性),他想不出该 ...

  9. LAMP+YII框架配置中遇到的问题

    以下列出了不同问题及答案: 1. 在yii框架中,改动数据库信息,主要有main.php和database.php两个文件. 2. 问题: watermark/2/text/aHR0cDovL2Jsb ...

  10. sql%rowcount 返回影响行数

    oracle中.返回影响行数是:If sql%rowcount 举例: update ut_calenderStatus t set t.calenderstatus=pi_flg, t.m=pi_M ...