LINEOUTSIDExe
d
WHILE做好计数器
declarex
umberbegi
x0whilex3loopxx1DBMS_OUTPUTPUT_LINEINSIDExe
dloopDBMS_OUTPUTPUT_LINEOUTPUTxe
d
Loopbegi
forii
由大到小,reverse15looporacle中,递增量只能是默认的1DBMS_OUTPUTPUT_LINEIi
fe
dloopDBMS_OUTPUTPUT_LINEovere
d
goto语句declarex
umberbegi
x0repeat_loop标记xx1DBMS_OUTPUTPUT_LINExifx3the
gotorepeat_loopgoto到标记处e
dife
d
专门处理
declareaavarchar232begi
selectcidi
toaafromhise_co
tractwhererow_id1111DBMS_OUTPUTput_li
eaaexceptio
whe
NO_DATA_FOUNDthe
DBMS_OUTPUTput_li
eWRONGe
d
f通用异样,exceptio
whe
othersthe
retur
eg
exceptio
whe
othersthe
rollbackas_retur
1raise_applicatio
_error20200处理错误sqlcodesqlerrmas_msg处理错误sqlcodesqlerrmretur
自定义专门
declaret
amevarchar232eexceptio
专门类型begi
selectcidi
tot
amefromhise_co
tractwhererow_id111ift
amehhpasswordthe
选出的结果是hhpasswordraisee抛出专门e
difDBMS_OUTPUTput_li
et
ameexceptio
whe
ethe
DBMS_OUTPUTput_li
eNODATAFOUND
fe
d复合变量,记录
记录:Typetype_
ameisrecordVariable_
amedatatypeVariable_
amedatatype使用的时候:real_
ametype_
ame
f游标cursor:
游标并不是一种数据库对象
游标:是一种PLSQL操纵结构,能够对SQL语句的处理进行显示操纵,便于对表的行数据逐条进行处理。
游标分为:显式,隐式
游标的属性:FOUNDISOPEN当游标被打开时,ISOPEN属性为trueNOTFOUNDROWCOUNT
显示游标:
declarecursormycurisselectrow_idcidfromhise_co
tractmyrecordhise_co
tractrowtype游标中的数据取出放到相应的变量中。以记录的方式〔myrecordhise_co
tractrowtype〕和一个表紧密相关begi
ope
mycur打开游标fetchmycuri
tomyrecord把游标放置到对应变量中,对应的是select语句表的数据的第一条。whilemycurFOUNDLOOP只有要数据,就取,一直取到游标结果集的底部DBMS_OUTPUTPUT_LINEmyrecordrow_idmyrecordcid变量与表的字段一致fetchmycuri
tomyrecord循环中连续取e
dloopclosemycur关闭游标,e
d
利用游标参数对数据的操纵〔显式游标〕
declarecursorcur_paraidvarchar2is参数不需要加入长度,只要类型selectcidfromhise_co
tractwherecididt_cidhise_co
tractcidtypebegi
ope
cur_para0001
floopfetchcur_parai
tot_cidexitwhe
cur_paraNOTFOUNDDBMS_OUTPUTPUT_LINEt_cide
dloopclosecur_parae
d
利用for循环,不需要打开和关闭游标
declarecursorcur_paraidvarchar2is参数不需要加入长度,只要类型selectcidfromhise_co
tractwherecidr