第乙個應用得知更新的行數
1、隱式游標在正常執**況下更新的行數並不知道,可以根據sql%rowcount得知更新的行數
set serveroutput on
begin
update student
set first_name=
'd'where first_name like
'd%'
;dbms_output.put_line(
sql%
rowcount);
end;
2、sql%count也可以用來校驗select得到的條數個數
set serveroutput on
declare
v_city zipcode.city%
type
;begin
select city into v_city
from zipcode
where zip=
07002;if
sql%
rowcount=1
then
dbms_output.put_line(v_city||
' has a zip code of 07002');
elsif sql
%rowcount=0
then
dbms_output.put_line(
'the zip code 07002 is not in the database');
else
dbms_output.put_line(
'stop harassing me');
end;
第二個應用方式其實可以從異常角度出發:
set serveroutput on
declare
v_city zipcode.city%
type
;begin
select city into v_city
from zipcode
where zip=
07002
;exception
when no_data_found then
dbms_output.put_line(
'the zip code 07002 is not in the database');
dbms_output.put_line(v_city||
' has a zip code of 07002');
when too_many_rows then
dbms_output.put_line(
sql%
rowcount
||',zip is not the only one');
end;
第三個應用中為了避免更新出錯或者刪除出錯,可以根據更新或者刪除的總數來判斷我是否是誤操作
begin
delete
from zipcode where zip=
07002
; dbms_output.put_line(
'sum of delete data is '
||sql
%rowcount);
if(sql%
rowcount
<10)
then
commit
;else
rollback
;endif;
exception
when others then
dbms_output.put_line(
'update data errors');
end;
mysql隱式游標 MYSQL 游標 動態游標示例
mysql沒有隱式和顯式游標之分,所用的游標都是顯式游標,也就是必須要進行定義游標變數,然後按照正規的流程使用,開啟 遍歷 關閉。以下是具體的使用方法。游標定義 1.declare cursor name cursor for select statement 游標操作 open 開啟游標 1.op...
Oracle隱式游標和顯式游標
oracle隱式游標和顯式游標,游標是什麼?就是在記憶體開闢的一塊臨時儲存空間。1.1oracle有常用的哪些隱式游標 1.2 oracle隱式游標演示 隱式游標 使用的表為oracle預設自帶的emp表 sql rowcount 影響記錄條數 sql found 是否有滿足條件的記錄 set se...
PL SQL 隱式游標
1.更新emp表中一名員工的資訊,並通過游標的屬性檢視被更新的記錄數 sql set serveroutput on sql declare 2 begin 3 update emp 4 set sal 1200 5 where empno 7369 6 if sql notfound then 7...