oracle package 小例子,以及一个存储过程的应用
Java代码
- create or replace package query_project_pck
- as
- type pro_ref_cursor_type is ref cursor;
- type pro_table is table of varchar(100);
- type pro_record is record(name varchar(100),id varchar(100));
- procedure pro_procedure(name varchar,id varchar);
- end query_project_pck; -- define package
- create or replace procedure query_pro(pro_result out query_project_pck.pro_ref_cursor_type) is
- begin
- open pro_result for
- select pro.xmid, pro.xmmc,pro.updatetime from T_LPROMIS_XMGL_GBBXMXX pro return pro_record_type;
- end; --create procedure using ref cursor
- -- test procedure using ref cursor
- declare
- pro_cursor query_project_pck.pro_ref_cursor_type;
- id T_LPROMIS_XMGL_GBBXMXX.Xmid%type;
- name T_LPROMIS_XMGL_GBBXMXX.Xmmc%type;
- pro_record pro_record_type;
- begin
- query_pro(pro_cursor);
- loop
- fetch pro_cursor
- into pro_record;
- exit when pro_cursor%notfound;
- dbms_output.put_line(pro_record.id || ' ' || pro_record.name || ' '|| pro_record.updatetime );
- end loop;
- close pro_cursor;
- --for pro_record in pro_cursor loop
- -- dbms_output.put_line(pro_record.xmid,pro_record.xmmc);
- --end loop;
- end;