【PL/SQL 學習】隱式遊標學習
--oracle 會為每一個非顯示遊標的sql dml 語句都建立一個隱式遊標,隱式遊標也稱為sql 遊標。與顯示遊標不同,不能對一個隱式遊標執行open,close和fetch語句。oracle 隱式的開啟sql遊標,處理sql遊標,然後再關閉該遊標。
declare
vid t.object_id%type;
vowner t.owner%type;
begin
select object_id ,owner into vid,vowner from t where rownum <2;
if sql%isopen then
dbms_output.put_line('it is not possiable');
else
dbms_output.put_line('vid is '||vid||' vowner is '||vowner);
dbms_output.put_line('%isopen 的屬性為false');
end if;
end;
輸出為:
vid is 1 vowner is SYS
%isopen 的屬性為false
--和顯示遊標一樣,隱式遊標也有四大屬性%FOUND,%ISOPEN,%NOTFOUND,%ROWCOUNT.由於隱式遊標沒有名次,oracle提供了一種方法在屬性前面加 關鍵字 SQL,這樣我們就可以使用這些屬性了。
例子如下:
declare
vid t.object_id%type;
vowner t.owner%type;
rowsnum integer;
begin
select object_id ,owner into vid,vowner from t where rownum <2;
rowsnum := sql%rowcount;
dbms_output.put_line('vid is '||vid||' vowner is '||vowner);
dbms_output.put_line('rowsnum is '||rowsnum);
if sql%found then
dbms_output.put_line('sql%found is true;');
else
dbms_output.put_line('sql%found is false;');
end if;
if sql%notfound then
dbms_output.put_line('sql%notfound is true;');
else
dbms_output.put_line('sql%notfound is false;');
end if;
end;
輸出為:
vid is 1 vowner is SYS
rowsnum is 1
sql%found is true;
sql%notfound is false;
declare
vid t.object_id%type;
vowner t.owner%type;
begin
select object_id ,owner into vid,vowner from t where rownum <2;
if sql%isopen then
dbms_output.put_line('it is not possiable');
else
dbms_output.put_line('vid is '||vid||' vowner is '||vowner);
dbms_output.put_line('%isopen 的屬性為false');
end if;
end;
輸出為:
vid is 1 vowner is SYS
%isopen 的屬性為false
--和顯示遊標一樣,隱式遊標也有四大屬性%FOUND,%ISOPEN,%NOTFOUND,%ROWCOUNT.由於隱式遊標沒有名次,oracle提供了一種方法在屬性前面加 關鍵字 SQL,這樣我們就可以使用這些屬性了。
例子如下:
declare
vid t.object_id%type;
vowner t.owner%type;
rowsnum integer;
begin
select object_id ,owner into vid,vowner from t where rownum <2;
rowsnum := sql%rowcount;
dbms_output.put_line('vid is '||vid||' vowner is '||vowner);
dbms_output.put_line('rowsnum is '||rowsnum);
if sql%found then
dbms_output.put_line('sql%found is true;');
else
dbms_output.put_line('sql%found is false;');
end if;
if sql%notfound then
dbms_output.put_line('sql%notfound is true;');
else
dbms_output.put_line('sql%notfound is false;');
end if;
end;
輸出為:
vid is 1 vowner is SYS
rowsnum is 1
sql%found is true;
sql%notfound is false;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22664653/viewspace-687917/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- PL/SQL 學習日記SQL
- PL/SQL 遊標SQL
- PLSQL學習-【5遊標】SQL
- PL/SQL學習筆記-1SQL筆記
- PL/SQL學習筆記-2SQL筆記
- PL/SQL學習筆記-3SQL筆記
- PL/SQL學習筆記-4SQL筆記
- PL/SQL學習筆記-5SQL筆記
- PL/SQL學習筆記-6SQL筆記
- [PL/SQL]10g PL/SQL學習筆記(一)SQL筆記
- [PL/SQL]10g PL/SQL學習筆記(二)SQL筆記
- [PL/SQL]10g PL/SQL學習筆記(三)SQL筆記
- PL/SQL學習筆記-總結SQL筆記
- Oracle之PL/SQL基礎學習OracleSQL
- PL/SQL 04 遊標 cursorSQL
- 【PL/SQL】遊標提取迴圈SQL
- PL/Sql循序漸進全面學習教程--OracleSQLOracle
- 【PL/SQL 學習】PLS-00201SQL
- Oracle之PL/SQL基礎學習之二OracleSQL
- 【SQL 學習】case 表示式SQL
- PL/SQL-遊標和遊標變數的使用SQL變數
- SQL Server遊標使用練習SQLServer
- 遊標的學習
- PL/SQL經典學習筆記(6-10)SQL筆記
- PL/SQL經典學習筆記(2-5)SQL筆記
- Oracle學習筆記整理之遊標篇Oracle筆記
- oracle學習筆記(十七) PL/SQL高階應用Oracle筆記SQL
- 有關使用PL/SQL提高效能的學習:SQL
- pl/sql練習SQL
- pl/sql 練習SQL
- 資料庫學習筆記——20 使用遊標資料庫筆記
- Oralce之PL/SQL程式設計(遊標)SQL程式設計
- SQL 學習SQL
- sql學習SQL
- 隱式遊標(implicit cursor)_sql%found_rowcount小操作SQL
- 【SQL 學習】函式之DECODE()SQL函式
- Oracle使用cursor for隱式遊標Oracle
- 學習目標