您的位置:首页 > 博客中心 > 数据库 >

oracle 存储过程

时间:2022-03-15 04:28

 简要记录存储过程语法与Java程序的调用方式

  一 存储过程

    首先,我们建立一个简单的表进行存储过程的测试

createtable
xuesheng(id integer, xing_ming varchar2(25), yu_wen number, shu_xue number);

insertinto xuesheng values(1,‘zhangsan‘,80,90)
insertinto xuesheng values(2,‘lisi‘,85,87)

1)无返回值的存储过程

createorreplaceprocedure xs_proc_no is
begin
insertinto xuesheng values (3, ‘wangwu‘, 90, 90);
commit;
end xs_proc_no;

2)有单个数据值返回的存储过程

gxlsystem.com,布布扣

上述存储过程修改完毕。另外,一个复杂的工程项目中的例子:查询一段数据中间隔不超过十分钟且连续超过100条的数据。即上述代码所调用的getdcsj存储过程

create or replace procedure getDcsj(var_flag     in varchar2,                                     var_jzbh     in varchar2,                                     number_total out number,                                     var_cursor_a out mypackage.my_cursor,                                     var_cursor_b out mypackage.my_cursor) is   total number;   cursor cur is     select sj, flag       from d_dcsj      where jzbh = var_jzbh      order by sj desc        for update;   last_time date; begin   for cur1 in cur loop     if last_time is null or cur1.sj >= last_time - 10 / 60 / 24 then       update d_dcsj set flag = var_flag where current of cur;       last_time := cur1.sj;     else       select count(*) into total from d_dcsj where flag = var_flag;       dbms_output.put_line(total);       if total < 100 then         update d_dcsj set flag = null where flag = var_flag;         last_time := null;         update d_dcsj set flag = var_flag where current of cur;       else         open var_cursor_a for           select *             from d_dcsj            where flag = var_flag              and jzbh = var_jzbh              and zh = ‘A‘            order by sj desc;         number_total := total;         open var_cursor_b for           select *             from d_dcsj            where flag = var_flag              and jzbh = var_jzbh              and zh = ‘B‘            order by sj desc;         number_total := total;         exit;       end if;     end if;   end loop;   select count(*) into total from d_dcsj where flag = var_flag;   dbms_output.put_line(total);   if total < 100 then     open var_cursor_a for       select * from d_dcsj where zh = ‘C‘;     open var_cursor_b for       select * from d_dcsj where zh = ‘C‘;   else     open var_cursor_a for       select *         from d_dcsj        where flag = var_flag          and jzbh = var_jzbh          and zh = ‘A‘        order by sj desc;     number_total := total;     open var_cursor_b for       select *         from d_dcsj        where flag = var_flag          and jzbh = var_jzbh          and zh = ‘B‘        order by sj desc;     number_total := total;   end if;   commit; end; /

Oracle 存储过程,布布扣,bubuko.com

热门排行

今日推荐

热门手游