|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
使用它开发程序也是非常简单的。”利用Cursor:
declare
RoomIDRoom.RoomID%Type;
RoomNameRoom.RoomName%Type;
cursorcrRoomis
selectRoomID,RoomName
fromRoom;
begin
opencrRoom;
loop;
fetchcrRoomintoRoomID,RoomName;
exitwhencrRoom%notFound;
endloop;
closecrRoom;
end;
3.1在游标利用出口参数
在SQL语句的Where子句中得当利用相干语句简化逻辑,原本必要利用两个游标,把相干出口参数放进到SQL语句的Where子句中,一个就弄定了:
cursorcrRoomis
select
distinct楼层,衡宇用处
fromTT_没有处置的衡宇t
where数据级别>=0
and衡宇处置种别=3
and产权编号=p_产权编号
and拆迁衡宇种别=p_拆迁衡宇种别
and面积>0
and(notp_衡宇用处isnull
and衡宇用处=p_衡宇用处
orp_衡宇用处isnull);
别的一个例子:
CREATEORREPLACEPROCEDUREPrintStudents(
p_MajorINstudents.major%TYPE)AS
CURSORc_StudentsIS
SELECTfirst_name,last_name
FROMstudents
WHEREmajor=p_Major;
BEGIN
FORv_StudentRecINc_StudentsLOOP
DBMS_OUTPUT.PUT_LINE(v_StudentRec.first_name||||
v_StudentRec.last_name);
ENDLOOP;
END;
Oracle带的例子examp6.sql
DECLARE
CURSORbin_cur(part_numberNUMBER)ISSELECTamt_in_bin
FROMbins
WHEREpart_num=part_numberAND
amt_in_bin>0
ORDERBYbin_num
FORUPDATEOFamt_in_bin;
bin_amtbins.amt_in_bin%TYPE;
total_so_farNUMBER(5):=0;
amount_neededCONSTANTNUMBER(5):=1000;
bins_looked_atNUMBER(3):=0;
BEGIN
OPENbin_cur(5469);
WHILEtotal_so_far<amount_neededLOOP
FETCHbin_curINTObin_amt;
EXITWHENbin_cur%NOTFOUND;
/*Ifweexit,theresnotenoughto*
*satisfytheorder.*/
bins_looked_at:=bins_looked_at+1;
IFtotal_so_far+bin_amt<amount_neededTHEN
UPDATEbinsSETamt_in_bin=0
WHERECURRENTOFbin_cur;
--takeeverythinginthebin
total_so_far:=total_so_far+bin_amt;
ELSE--wefinallyhaveenough
UPDATEbinsSETamt_in_bin=amt_in_bin
-(amount_needed-total_so_far)
WHERECURRENTOFbin_cur;
total_so_far:=amount_needed;
ENDIF;
ENDLOOP;
CLOSEbin_cur;
INSERTINTOtempVALUES(NULL,bins_looked_at,<-binslookedat);
COMMIT;
END;
--Createdon2004-8-9byADMINISTRATOR
declare
--带有变量的Cursor
cursorcrBooks(c_bookTitlevarchar2)is
select*
frombooksa
wherea.titlelikec_bookTitle||%;
begin
forv_BooksincrBooks(Oracle8)loop
dbms_output.put_line(v_Books.author1);
endloop;
end;如果你在一个遵循GPL的自由(开源)项目中使用MySQL,那么你可以遵循GPL协议使用MySQL。然而,如果你的项目不是在GPL协议下的话,你必须为使用MySQL来支付许可费用,或者你可能因为这个因素而将你的项目改为遵循GPL。 |
|