日期:2014-05-17 浏览次数:21162 次
declare type nestable_type_varchar2 is table of varchar2(10); nestable_varchar2 nestable_type_varchar2 := nestable_type_varchar2(null); type map_type_varchar2 is table of varchar2(10) index by binary_integer; map_varchar2 map_type_varchar2; type array_type_varchar2 is varray(10) of varchar2(10); array_varchar2 array_type_varchar2 := array_type_varchar2('123'); type record_type_dept is record ( deptNo number(2), deptName varchar2(14) ); type nestable_type_dept is table of record_type_dept; nestable_dept nestable_type_dept; type array_type_dept is varray(10) of record_type_dept; array_dept array_type_dept; xx boolean; begin dbms_output.put_line('nestable_varchar2.count: ' || nestable_varchar2.count); dbms_output.put_line('map_varchar2.count: ' || map_varchar2.count); dbms_output.put_line('array_varchar2.count: ' || array_varchar2.count); xx := array_varchar2.exists(12); dbms_output.put_line('array_varchar2.exists(12): ' || case when xx then 'yes' else 'no' end); dbms_output.put_line('nestable_dept.count: ' || nestable_dept.count); dbms_output.put_line('array_dept.count: ' || array_dept.count); dbms_output.put_line(1 / 0); exception when others then dbms_output.put_line('exception found.'); end;
SQL> DECLARE 2 type array_type_varchar2 is varray(10) of varchar2(10); 3 array_varchar2 array_type_varchar2 := array_type_varchar2('123'); 4 xx BOOLEAN; 5 BEGIN 6 dbms_output.put_line('=='||array_varchar2(1)); 7 xx:=array_varchar2.exists(12); 8 dbms_output.put_line('array_varchar2.exists(12): ' 9 || case when xx then 'yes' else 'no' end); 10 END; 11 / ==123 array_varchar2.exists(12): yes PL/SQL 过程已成功完成。 SQL> DECLARE 2 type array_type_varchar2 is varray(10) of varchar2(10); 3 array_varchar2 array_type_varchar2 := array_type_varchar2('123'); 4 xx BOOLEAN; 5 BEGIN 6 --dbms_output.put_line('=='||array_varchar2(1)); 7 xx:=array_varchar2.exists(12); 8 dbms_output.put_line('array_varchar2.exists(12): ' 9 || case when xx then 'yes' else 'no' end); 10 END; 11 / array_varchar2.exists(12): no PL/SQL 过程已成功完成。
------解决方案--------------------
PL/SQL块同样是以数据库对象为操作对象,但由于SQL本身不具备过程控制功能,所以为了能够与其他语言一样具备过程控制的处理功能,在SQL中加入诸如循环和选择等面向过程的处理功能,由此形成了PL/SQL。所