Home > Database > Mysql Tutorial > body text

oracle游标循环和时间函数实例

WBOY
Release: 2016-06-07 14:54:48
Original
1129 people have browsed it

无详细内容 Oracle 游标 -- 时间函数实例:select sysdate,add_months(sysdate,12) from dual; --加1年select sysdate,add_months(sysdate,1) from dual; --加1月select sysdate,to_char(sysdate+7,'yyyy-mm-dd HH24:MI:SS') from dual; --加1星期select sysda

Oracle 游标
-- 时间函数实例:

select sysdate,add_months(sysdate,12) from dual;        --加1年
select sysdate,add_months(sysdate,1) from dual;        --加1月
select sysdate,to_char(sysdate+7,'yyyy-mm-dd HH24:MI:SS') from dual;   --加1星期
select sysdate,to_char(sysdate+1,'yyyy-mm-dd HH24:MI:SS') from dual;   --加1天
select sysdate,to_char(sysdate+1/24,'yyyy-mm-dd HH24:MI:SS') from dual;  --加1小时
select sysdate,to_char(sysdate+1/24/60,'yyyy-mm-dd HH24:MI:SS') from dual;  --加1分钟
select sysdate,to_char(sysdate+1/24/60/60,'yyyy-mm-dd HH24:MI:SS') from dual;  --加1秒

-- 游标循环实例:

-- 查询出多条数据,但是需要一一循环出来,类似java里的遍历

declare
v_yhzh varchar2(20); --定义变量用户号
v_phone varchar2(11); --手机号
CURSOR cur_1 IS select dy.user_sid,dy.user_mobile  from dx.dy_order dy; --将结果存入cur_1
begin
  open cur_1; --打开游标
  loop   --循环
    fetch cur_1 into v_yhzh,v_phone; --依次将游标的值给v_yhzh
    exit when cur_1%notfound; --循环的条件
    dbms_output.put_line(v_yhzh||'---'||v_phone); --打印输出
    end loop; --循环结束 内陆运输
    close cur_1;  --关闭游标
end; --结束
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template