隱式遊標(implicit cursor)_sql%found_rowcount小操作
#sql%found用於dml(delete,update,insert)及select into是否真正的操作了表
SQL> desc dept;
Name Null? Type
----------------------------------------- -------- ----------------------------
ID NUMBER(38)
NAME VARCHAR2(20)
SQL> desc dept;
Name Null? Type
----------------------------------------- -------- ----------------------------
ID NUMBER(38)
NAME VARCHAR2(20)
SQL> declare
2 v_name varchar2(20):='zxy';
3 begin
4 delete from dept where name=v_name;
5 if sql%found then
6 dbms_output.put_line('the record deleted');
7 insert into dept values(10,'other');
8
9 end if;
10 end;
11 /
the record deleted
2 v_name varchar2(20):='zxy';
3 begin
4 delete from dept where name=v_name;
5 if sql%found then
6 dbms_output.put_line('the record deleted');
7 insert into dept values(10,'other');
8
9 end if;
10 end;
11 /
the record deleted
PL/SQL procedure successfully completed.
SQL> select * from dept;
ID NAME
---------- --------------------
10 other
---------- --------------------
10 other
#sql%rowcount用於dml及select into影響表的多少行記錄
SQL> select * from dept;
SQL> select * from dept;
ID NAME
---------- --------------------
10 other
---------- --------------------
10 other
SQL> declare
2 v_name varchar2(20):='zxy';
3 begin
4 delete from dept where name=v_name;
5 dbms_output.put_line(to_char(sql%rowcount)||' number of dept deleted');
6 end;
7 /
0 number of dept deleted
2 v_name varchar2(20):='zxy';
3 begin
4 delete from dept where name=v_name;
5 dbms_output.put_line(to_char(sql%rowcount)||' number of dept deleted');
6 end;
7 /
0 number of dept deleted
PL/SQL procedure successfully completed.
SQL>
#sql%notfound
SQL> declare
2 v_name varchar2(20):='zxy';
3 begin
4 delete from dept where name=v_name;
5 if sql%notfound then
6 dbms_output.put_line('not found the record');
7 insert into dept values(88,v_name);
8 else
9 dbms_output.put_line('table dept total records '||to_char(sql%rowcount));
10 end if;
11 end;
12 /
not found the record
PL/SQL procedure successfully completed.
SQL> select * from dept;
ID NAME
---------- --------------------
10 other
88 zxy
---------- --------------------
10 other
88 zxy
SQL>
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-665812/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle使用cursor for隱式遊標Oracle
- SQL 遊標cursorSQL
- PL/SQL 04 遊標 cursorSQL
- SQL 遊標cursor的運用SQL
- 【PL/SQL 學習】隱式遊標學習SQL
- 【CURSOR】Oracle 遊標 (cursor)知識梳理Oracle
- v$sql v$sqlarea v$sql_shared_cursor及遊標SQL
- v$sql v$sqlarea v$sql_shared_cursor及父遊標,子游標SQL
- PLSQL 呼叫 返回 遊標(Cursor)PROCEDURESQL
- oracle cursor遊標迴圈比較遊標元素是否相同Oracle
- flask-sqlalchemy中使用cursor遊標FlaskSQL
- oracle cursor遊標獲取首末元素Oracle
- SQL 遊標SQL
- Denoising Diffusion Implicit Models(去噪隱式模型)模型
- Oracle遊標共享(Cursor Sharing)--常規遊標共享和自適應遊標共享(ACS)Oracle
- PLC結構化文字(ST)——隱式列舉(implicit enum)
- 利用隱式遊標分批刪除資料的procedure
- PL/SQL 遊標SQL
- SQL Server遊標SQLServer
- Operator運算子過載與Implicit隱式型別轉換型別
- V$SQL_遊標、adaptive cursor sharing、bind peeking、直方圖的概念SQLAPT直方圖
- Sql Server系列:遊標SQLServer
- 【CSS: cursor】滑鼠游標指標樣式大全CSS指標
- SQL Server實戰六:T-SQL、遊標、儲存過程的操作SQLServer儲存過程
- oracle pl/sql儲存過程內外層遊標cursor巢狀引數化示例OracleSQL儲存過程巢狀
- PL/SQL-遊標和遊標變數的使用SQL變數
- 簡單測試動態遊標(REF CURSOR)的使用
- 什麼是SQL遊標?SQL
- SQL Server遊標使用例子SQLServer
- 資料庫操作之遊標資料庫
- Oracle自適應共享遊標——Adaptive Cursor Sharing(上)OracleAPT
- Oracle自適應共享遊標——Adaptive Cursor Sharing(下)OracleAPT
- 從共享遊標shared cursor角度看forall批量繫結
- sql隱式轉換SQL
- SQL Server遊標使用練習SQLServer
- SQL Server基礎之遊標SQLServer
- 【PL/SQL】遊標提取迴圈SQL
- 【CURSOR】Oracle 子游標無法共享的原因之V$SQL_SHARED_CURSOROracleSQL