分类: Oracle
2011-04-29 10:24:46
sql%NOTFOUND --update,delete操作时没找到符合条件的记录。
sql%FOUND --SELECT columnname INTO ,update,delete找到符合条件的记录Top
sql%rowcount --判定当前更新记录数
sql%isopen --判定当前游标是否打开Top
%FOUND
This attribute yields TRUE if an INSERT, UPDATE, or DELETE statement affected one or more rows or a SELECT INTO statement returned one or more rows. Otherwise, it yields FALSE.
%ISOPEN
This attribute always yields FALSE because Oracle closes the SQL cursor automatically after executing its associated SQL statement.
%NOTFOUND
This attribute is the logical opposite of %FOUND. It yields TRUE if an INSERT, UPDATE, or DELETE statement affected no rows, or a SELECT INTO statement returned no rows. Otherwise, it yields FALSE.
%ROWCOUNT
This attribute yields the number of rows affected by an INSERT, UPDATE, or DELETE statement, or returned by a SELECT INTO statement.
在执行任何DML语句前SQL%FOUND和SQL%NOTFOUND的值都是NULL,在执行DML语句后,SQL%FOUND的属性值将是:
. TRUE :INSERT
. TRUE :DELETE和UPDATE,至少有一行被DELETE或UPDATE.
. TRUE :SELECT INTO至少返回一行
当SQL%FOUND为TRUE时,SQL%NOTFOUND为FALSE。
SQL%ROWCOUNT
在执行任何DML语句之前,SQL%ROWCOUNT的值都是NULL,对于SELECT INTO语句,如果执行成功,SQL%ROWCOUNT的值为1,如果没有成功,SQL%ROWCOUNT的值为0,同时产生一个异常NO_DATA_FOUND.
SQL%ISOPEN
SQL%ISOPEN是一个布尔值,如果游标打开,则为TRUE, 如果游标关闭,则为FALSE.对于隐式游标而言SQL%ISOPEN总是FALSE,这是因为隐式游标在DML语句执行时打开,结束时就立即关闭。
-----------------------------
--sql%返回最后一次dml语句的值
select XX into ls_xx from test_1 where id0000='XX';
如果返回行数不为1,则报错,可适当运用组函数或加where rownum=1条件。