判断语句:if 条件 then
   if  条件  then ************;
   elsif  条件  then  ************;
   elsif 条件  then ************;
   end if;
  end if;

主要注意elsif 写法,少一个e

时间查询:to_char(t.uptime,'yyyy-mm-dd')='2015-10-27',用to_char函数转成字符型

和分页查询有关的存储过程:

create or replace procedure PROC_GET_CREATETASK
(
  var_regionCode in char := '',
  var_rwlx in nvarchar2 := '',
  var_uptime in nvarchar2 := '',
  var_orderfield in nvarchar2 := '',      
  var_ordertype in nvarchar2 := '',        
  var_pageindex in out number,          
  var_pagesize in out number,            
  var_totalRecords out number,          
  var_ret out SYS_REFCURSOR
)
is
  v_sql VARCHAR2(4000) := '';             
  v_sqlCount VARCHAR2(4000) := '';        
  v_where VARCHAR2(4000) := 'WHERE 1=1 and sftask=''鍚?'';
  v_totalPages number := 0;
  v_startRecord Number(10);               
  v_endRecord Number(10);                 
begin
  if var_regionCode is not null then
   if  var_regionCode='000000'  then v_where := v_where;
   elsif  substr(var_regionCode,3,4)='0000' then
    v_where := v_where || ' AND substr(t.xzqdm,0,2)=''' || substr(var_regionCode,1,2) || '''';
   elsif substr(var_regionCode,5,2)='00' then
    v_where := v_where || ' AND substr(t.xzqdm,0,4)=''' || substr(var_regionCode,1,4) || '''';
   end if;
  end if;

if var_rwlx is not null then
    v_where := v_where || ' AND t.RWLX = '''|| var_rwlx || '''';
  end if;
         
  if var_uptime is not null then
    v_where := v_where || ' AND to_char(t.uptime,''yyyy-mm-dd'') = ''' || var_uptime || '''';
  end if;

v_sql := v_sql || 'select rownum r,t.*  from VIEW_TASKMANAGE t ' || v_where;

v_sqlCount := v_sqlCount || 'select count(*) from (' || v_sql || ')';

execute immediate v_sqlCount into var_totalRecords;
        
  if var_orderfield <> '' then
    v_sql := v_sql || 'order by var_orderfield ';
  end if;

if var_ordertype <> '' then
    v_sql := v_sql || var_ordertype;
  end if;
                  
  if var_totalRecords > 0 then
  begin
    v_totalPages := ceil(var_totalRecords / var_pagesize);

if var_pageIndex < 1 then
      var_pageIndex := 1;
    end if;
    
    if var_pageIndex > v_totalPages then
      var_pageIndex := v_totalPages;
    end if;

v_startRecord := (var_pageIndex - 1) * var_pagesize + 1;
    v_endRecord := var_pageIndex * var_pagesize;
             
    v_sql := 'SELECT * FROM (' || v_sql || ') a where a.r between ' || v_startRecord || ' and ' || v_endRecord;
  end;
         
  end if;
         
  open var_ret for v_sql;

end PROC_GET_CREATETASK;

Oracle 存储过程判断语句正确写法和时间查询方法的更多相关文章

  1. Oracle存储过程中跳出循环的写法

    注:本文来源于: <  Oracle存储过程中跳出循环的写法   > Oracle存储过程中跳出循环的写法 记录exit和return的用法 1:exit用来跳出循环 loop IF V_ ...

  2. Oracle 存储过程调用语句

    #oracle 存储过程调用语句declare v_custName varchar2(10); --客户姓名 v_num number; --订单分布天数 v_time number; --每日订单 ...

  3. SQL判断语句用法和多表查询

    1.格式化时间sql语句 本例中本人随便做了两张表,和实际不是很相符,只是想说明sql语句的写法. 例1表格式如下: 需求:查询出本表,但需要使time字段的时间格式为yyyy-MM-dd,比如:20 ...

  4. 8.Smarty的条件判断语句的写法

    {if $newObj eq 'a'} welcome a {elseif $a eq 'b'} welcome b {else} welcome others {/if}

  5. SSE图像算法优化系列十六:经典USM锐化中的分支判断语句SSE实现的几种方法尝试。

    分支判断的语句一般来说是不太适合进行SSE优化的,因为他会破坏代码的并行性,但是也不是所有的都是这样的,在合适的场景中运用SSE还是能对分支预测进行一定的优化的,我们这里以某一个算法的部分代码为例进行 ...

  6. oracle一条语句插入多个值的方法

    今天在实践过程中遇到一个问题, 我想往数据库插入多条数据时,使用了如下语句: insert into 表1 (字段1,字段2) values (1,2),(2,3),(3,4); 这条语句在mysql ...

  7. Oracle存储过程中不支持DML语言的解决方法(针对遇见的DROP关键字)

    ---存储过程中的原语句: ---删除表 DROP TABLE A_NEWTDDATA; --报错 经查询:存储过程不支持DML语言: 解决方法: execute immediate 'DROP TA ...

  8. 利用游标返回结果集的的例子(Oracle 存储过程)JAVA调用方法和.NET调用方法

    在sqlplus中建立如下的内容: 1.程序包 SQL> create or replace package types  2  as  3      type cursorType is re ...

  9. Oracle存储过程 使用游标、数组的配合查询

    查询输入的门牌号码是否在标准门牌库中存在.存在则返回相应的号码. public string GetValidate(){ OracleConnection conn = ConnectOra(); ...

随机推荐

  1. CodeForces 780 E Underground Lab

    Underground Lab 题解: 如果遍历一棵树,我们可以发现最多需要走的步数也不会超过2 * n步. 所以我们选出一棵树,然后遍历一边这颗树. 然后把序列分成k块就好了. 代码: #inclu ...

  2. lightoj 1134 - Be Efficient(组合数)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1134 题解:简单的一道组合题,现求一下前缀和,然后只要找前缀和膜m的结果相同的 ...

  3. 2017福建省赛 L Tic-Tac-Toe 模拟

    Kim likes to play Tic-Tac-Toe. Given a current state, and now Kim is going to take his next move. Pl ...

  4. 牛客网暑期ACM多校训练营(第三场) C Shuffle Cards 平衡树 rope的运用

    链接:https://www.nowcoder.com/acm/contest/141/C来源:牛客网 Eddy likes to play cards game since there are al ...

  5. 51nod 1086 背包问题 V2(二进制优化多重背包)

    题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1086 题解:怎么用二进制优化多重背包,举一个例子就明白了. ...

  6. poj 2253 Frogger(floyd变形)

    题目链接:http://poj.org/problem?id=1797 题意:给出两只青蛙的坐标A.B,和其他的n-2个坐标,任一两个坐标点间都是双向连通的.显然从A到B存在至少一条的通路,每一条通路 ...

  7. hdu5491 The Next 模拟

    Let LL denote the number of 1s in integer DD’s binary representation. Given two integers S1S1 and S2 ...

  8. linux中安装vsftpd出现的问题

    提示:安装vsftpd必须要在root用户下才能安装成功,进入root:su -(中间有空格) 问题: 1.再用命令getsebool -a | grep ftpd命令查看查看状态时出现的问题:SEL ...

  9. 内存泄露检测工具Valgrind

    内存泄露简介 什么是内存泄漏 内存泄漏(Memory Leak)是指程序中已动态分配的堆内存由于某种原因,程序未释放或无法释放,造成系统内存的浪费,导致程序运行速度减慢甚至系统崩溃等严重后果. 内存泄 ...

  10. 洛谷 P1525 关押罪犯 NOIp2010提高组 (贪心+并查集)

    题目链接:https://www.luogu.org/problemnew/show/P1525 题目分析 通过分析,我们可以知道,这道题的抽象意义就是把一个带边权的无向图,分成两个点集,使得两个集合 ...