Oracle 存储过程判断语句正确写法和时间查询方法
判断语句: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;
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?