a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 124|回复: 2

[其他] Oracle认证:Oracle通过存储过程返回数据集

[复制链接]
发表于 2012-8-4 13:41:06 | 显示全部楼层 |阅读模式
一、使用存储过程返回数据集 ' {& c' \2 Q* _
  Oracle中存储过程返回数据集是经由过程ref cursor类型数据的参数返回的,而返回数据的参数应该是out或in out类型的。0 G6 D* X# ~* m8 m& V2 B- c: K
  因为在界说存储过程时无法直接指定参数的数据类型为:ref cursor,而是首先经由过程以下体例将ref cursor进行了重界说:6 J% P" P( v2 N& V0 T
  create or replace package FuxjPackage is+ E. U6 U- b) v9 |- A+ Q
  type FuxjResultSet is ref cursor;! U. i1 b) b1 k% t
  --还可以界说其他内容
8 q  ?) q$ g, O' ?  end FuxjPackage;
1 `. H/ w0 R5 D9 W  再界说存储过程:
, U) |- V9 b. r6 ~/ b  create or replace procedure UpdatefuxjExample (sDM in char,sMC in char, pRecCur in out FuxjPackage.FuxjResultSet)
+ b$ z8 _& E' W+ I% w  as
, {$ C' ]  @0 a1 Q  begin
1 P! S# \- t) I6 w8 ^  update fuxjExample set mc=sMC where dm=sDM;
2 k5 m. n: @6 g' @( N  if SQL%ROWCOUNT=0 then
4 m1 M4 B1 K& t8 y2 b4 P. C& x/ o  rollback;
4 @* Q9 R7 ?( @1 ~5 k; S1 u2 _6 ^( x  open pRecCur for  p- W( q3 J0 q6 I" x
  select '0' res from dual;
0 V  i1 q2 g4 h- x' }! I/ w  else
% ]+ y6 {2 w! b  commit;
" U) Z  U5 G% A7 b& S8 e- `  open pRecCur for& H; P; `8 H! V+ R& {6 @) \
  select '1' res from dual;
8 t% Q8 ~, m8 E! Q$ n  end if;
% {! T  t3 O* `+ M$ @9 l  end;/ M$ Y" P6 c- Q, S6 x) M/ n- f. _  b
  和
/ F; x( m9 {0 n2 V, Y2 u5 @  create or replace procedure InsertfuxjExample (sDM in char,sMC in char, pRecCur in out FuxjPackage.FuxjResultSet)* U. S" `# O% |1 P  J
  as
( k: B& Y6 H" s' K! i  begin9 y' [7 r4 P3 m$ q; o% C
  insert into FuxjExample (dm,mc) values (sDM,sMC);
8 ~" F4 K3 V; Y  commit;3 y8 z2 l& Q; W9 O+ s' x* M, T, t; f3 B$ k
  open pRecCur for
; C1 {/ |1 K4 @# D- L  select * from FuxjExample;
1 y3 T" a: l3 r1 f: A0 a' g1 A9 r- }( k7 F6 q7 |( ]/ Z9 M
  end;
回复

使用道具 举报

 楼主| 发表于 2012-8-4 13:41:07 | 显示全部楼层

Oracle认证:Oracle通过存储过程返回数据集

</p>二、在Delphi中挪用返回数据集的存储过程
9 L( ?4 e  p. F3 v( |) U  可以经由过程TstoredProc或TQuery控件来挪用执行返回数据集的存储,数据集经由过程TstoredProc或TQuery控件的参数返回,注重参数的DataType类型为ftCursor,而参数的ParamType类型为ptInputOutput。
0 q6 a7 \1 c0 U1 z+ d7 b1 c  使用TstoredProc执行UpdatefuxjExample的相关设置为:% y9 }" q: s9 p  U8 C1 U0 J
  object StoredProc1: TStoredProc
, V- P2 Y& X8 M4 z8 L1 Z  DatabaseName = 'UseProc'+ I5 t9 o  y2 [& |9 ]8 i
  StoredProcName = 'UPDATEFUXJEXAMPLE'
( y9 [$ m! X# u0 D# Z4 s( P  ParamData = http://www.qnr.cn/pc/ora/study/201001/</pp  item/pp  DataType = ftString/pp  Name = 'sDM'/pp  ParamType = ptInput/pp  end/pp  item/pp  DataType = ftString/pp  Name = 'sMC'/pp  ParamType = ptInput/pp  end/pp  item/pp  DataType = ftCursor/pp  Name = 'pRecCur'/pp  ParamType = ptInputOutput/pp  Value = http://www.qnr.cn/pc/ora/study/201001/Null/pp  end>
  _# a( I- X8 P0 ^$ b0 J- c  end0 C' `9 R, a/ e) V
  执行体例为:2 o, ^6 l4 h" t& s# N: E+ P
  StoredProc1.Params.Items[0].AsString:=Edit1.Text; //给参数赋值;( {* U9 O4 z6 ^/ ^+ z  C3 v6 r
  StoredProc1.Params.Items[1].AsString:=Edit2.Text; //给参数赋值;: ?, Q. h/ P1 e* t$ z
  StoredProc1.Active:=False;* g7 n. q" G( a3 W+ V
  StoredProc1.Active:=True; //返回结不美观集
' P: D8 o' y# C) j. I  使用TQuery执行InsertfuxjExample的相关设置为:: @: Z, |! @0 L! \, U! d' `
  object Query1: TQuery
3 k5 I- B0 \: l  DatabaseName = 'UseProc'
  D- t2 F4 \" z) \+ j  SQL.Strings = (% Q2 ^9 M& \6 ]3 Q2 ?3 x$ i! g1 R3 ~
  'begin'
$ w. Q8 q8 `, t+ u1 z  ' InsertfuxjExample(sDM=>M,sMC=>:mc,pRecCur=>:RecCur);'6 Q. w1 o9 |; j7 J2 v' `) r
  'end;')5 S3 M4 I- Y4 {% B6 i( u: a
  ParamData = http://www.qnr.cn/pc/ora/study/201001/</pp  item/pp  DataType = ftString/pp  Name = 'DM'/pp  ParamType = ptInput/pp  end/pp  item/pp  DataType = ftString/pp  Name = 'mc'/pp  ParamType = ptInput/pp  end/pp  item/pp  DataType = ftCursor/pp  Name = 'RecCur'/pp  ParamType = ptInputOutput/pp  end># Y& M1 F  K  z& g5 ?! a
" c) B% b6 O. h7 h4 D* z) q
  end
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-8-4 13:41:08 | 显示全部楼层

Oracle认证:Oracle通过存储过程返回数据集

</p>  执行体例为:# ^0 R; P- m: c$ }: C3 y2 W
  Query1.Params.Items[0].AsString:=Edit3.Text; //给参数赋值;- i) `- }5 H, J
  Query1.Params.Items[1].AsString:=Edit4.Text; //给参数赋值;
6 a" x# Z6 `8 `! `# g  Query1.Active:=False;2 u# K2 K7 d+ M& \! c/ g
  Query1.Active:=True;
. H( B+ `2 s# h  if SQL%ROWCOUNT=0 then, W8 F0 g9 g9 j3 V6 g
  rollback;& s0 K+ T0 ^0 y+ b' v. r
  open pRecCur for
  E  G  C  i( Q8 V% c% \6 Z! U  select '0' res from dual;
0 G& Y4 s% h# N. E" R! {  else& s( F, _% E# ]
  commit;: s6 R3 D% b; ]2 \+ f7 Q
  open pRecCur for, X( t  R( U" R# M% e
  select '1' res from dual;* |+ [( O) Z6 ]5 D0 X% ?! L/ i
  end if;
" K, K: m# _) p# B/ w  U  end;
4 n. g5 ?4 [+ j  和5 m5 c$ n; e* w4 K- w
  create or replace procedure InsertfuxjExample (sDM in char,sMC in char, pRecCur in out FuxjPackage.FuxjResultSet)$ ~/ c9 l" N1 s/ r* S3 F
  as6 F! u1 B: j8 D9 ~$ q0 Q( k, w
  begin4 c, x! m2 P2 P' D
  insert into FuxjExample (dm,mc) values (sDM,sMC);
/ z* f; k/ P# d; D, B5 [8 o& \2 b  commit;0 f8 o8 j5 }3 R' T: H
  open pRecCur for, L2 W3 T; w' ~2 z/ ?' r
  select * from FuxjExample;  R! A/ D5 z. \! \
  end;
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Woexam.Com ( 湘ICP备18023104号 )

GMT+8, 2024-5-16 04:25 , Processed in 0.228966 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表