Chinaunix首页 | 论坛 | 博客
  • 博客访问: 52130
  • 博文数量: 42
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 399
  • 用 户 组: 普通用户
  • 注册时间: 2012-07-26 20:33
文章分类

全部博文(42)

文章存档

2014年(3)

2013年(39)

我的朋友

分类: Oracle

2014-02-26 17:04:03


  1. 1.
  2. CREATE OR REPLACE PACKAGE ROME AS
  3. AS
  4. TYPE RefCursor IS REF CURSOR;
  5. Function GetCompany(key IN char) return RefCursor;
  6. END;
  7. /
  8. CREATE OR REPLACE PACKAGE BODY ROME IS
  9. IS
  10. Function GetCompany(key IN char) return RefCursor
  11. Is
  12. v_temp RefCursor;
  13. BEGIN
  14. OPEN v_temp FOR
  15. SELECT * FROM Company WHERE com_ID =key;
  16. return v_temp;
  17. END GetCompany;
  18. END;
  19.   
  20. 2.(适用于PLSQL类型)
  21. Type shifts_ty is RECORD(
  22.      comp_code varchar2(10),
  23.      SHIFT_CODE varchar2(10),
  24.      sft_flg varchar2(10),
  25.      beg_tm number,
  26.      end_tm number,
  27.      skills varchar2(10)) ;
  28. Type shifts is Table of shifts_ty index by binary_integer;
  29.   
  30. FUNCTION test_proc(test varchar2)
  31.   
  32. return shifts is
  33. shiftspkg SHIFTS; --表变量shiftspkg
  34.   
  35. cursor q1 is select
  36. shifts.comp_code,shifts.shift_code,shifts.WRK_BEG_TM,shifts.WRK_end_TM,
  37. shifts.skills from str_shifts shifts where comp_code ='TSI'; --str_shifts是与表变量shiftspkg结构完全相同的真实表
  38. qty q1%rowtype;
  39. begin
  40.   
  41.      open q1;
  42.      loop
  43.          fetch q1 into qty;
  44.          exit when q1%notfound;
  45.       
  46.          for iCount in 1.. qty.skills.count
  47.          loop
  48.              shiftspkg(icount).comp_code:= qty.comp_code;
  49.              shiftspkg(icount).SHIFT_CODE:= qty.shift_code;
  50.              shiftspkg(icount).sft_flg:= 'SLOTS';
  51.              shiftspkg(icount).beg_tm:= qty.wrk_beg_tm;
  52.              shiftspkg(icount).end_tm:= qty.wrk_end_tm;
  53.              shiftspkg(icount).skills:= qty.skills(icount);
  54.          end loop;
  55.      end loop;
  56.      return shiftspkg;
  57. end;
  58. end;
  59.   
  60. 3.使用于SQL类型  
  61. create or replace type myScalarType as object
  62.     ( comp_code varchar2(10),
  63.       shift_code varchar2(10),
  64.       sft_flg varchar2(10),
  65.       beg_tm number,
  66.       end_tm number,
  67.       skills varchar2(10)
  68.        )
  69.   
  70. create or replace type myArrayType as table of myScalarType
  71.     
  72.      
  73. FUNCTION test_proc(test varchar2) return myArrayType
  74.      is
  75.          l_data myArrayType := myArrayType() ;
  76.      begin
  77.         for i in 1 .. 5
  78.         loop
  79.             l_data.extend;
  80.             l_data( l_data.count ) := myScalarType( 'cc-'||i,
  81.                                                     'sc-'||i,
  82.                                                     'flg-'||i,
  83.                                                     i,
  84.                                                     i,
  85.                                                     test||i );
  86.         end loop;
  87.      
  88.         return l_data;
  89.     end;
  90.      
  91.     end;
  92.   
  93. select *
  94.        from THE ( select cast( pkg_test.test_proc('hello') as myArrayType )
  95.                     from dual ) a

  96. select *
  97.        from table ( cast( my_function() as mytabletype ) )
  98.       order by seq

阅读(1665) | 评论(0) | 转发(0) |
0

上一篇:刪除windows服務

下一篇:没有了

给主人留下些什么吧!~~