PLSQL的SQL%NOTFOUND的使用场景

时间:2021-09-04 02:56:41
SELECT * INTO v_ticketStorageRow FROM BDM_TICKET_STORAGE
WHERE p_startTicketNo >= START_NO_ AND p_startTicketNo <= END_NO_;
IF SQL%FOUND
THEN
raise_application_error(-20000, '起始票号范围已经存在');
END IF;

 当select没有记录时IF SQL%FOUND并不会执行到,而是抛出NO_DATA_FOUND异常

这样的场景可以用select count(*) into v_recCout, 判断v_recCount不为0验证有无记录

SQL%FOUNDSQL%NOTFOUND在update和delete语句执行后可以正常用

对PLSQL的SQL%NOTFOUND的再验证

http://www.cnblogs.com/gaojian/archive/2012/11/23/2784471.html

NO_DATA_FOUND、SQL%NOTFOUND、SQL%ROWCOUNT的区别

http://hutianci.iteye.com/blog/386726