Bulk collect当没有数据抛出异常跟implicit cursor 处理不一样。
先看一下implicit cursor的处理吧:
cl scr;DECLARE l_descr hardware.descr%type;BEGIN SELECT descr INTO l_descr FROM hardware WHERE aisle = 0 AND item = 0; dbms_output.put_line('Item was found');EXCEPTIONWHEN no_data_found THEN dbms_output.put_line('Invalid item specified');END;
bulk collect的处理就不一样。
cl scr;DECLAREtype t_descr_listIS TABLE OF hardware.descr%type; l_descr_list t_descr_list;BEGIN SELECT descr bulk collect INTO l_descr_list FROM hardware WHERE aisle = 0 AND item = 0; IF l_descr_list.count = 0 THEN raise no_data_found; END IF; dbms_output.put_line('Item was found');EXCEPTIONWHEN no_data_found THEN dbms_output.put_line('Invalid item specified');END;