先贴上代码: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*Plus 运行时,输出如下:
nestable_varchar2.count: 1
map_varchar2.count: 0
array_varchar2.count: 1
array_varchar2.exists(12): yes
exception found.在PL/SQL developer 里运行时,输出的结果是这样:
nestable_varchar2.count: 1
map_varchar2.count: 0
array_varchar2.count: 1
array_varchar2.exists(12): no
exception found.由输出结果看出,PL/SQL developer的输出结果是正确的,array_varchar2.exists(12)应该返回为false!而SQL*Plus的输出结果是错误的!这是为什么呢,这么奇怪的结果输出?如果将抛异常的代码
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);注释掉,SQL*Plus的输出又正常了!
nestable_varchar2.count: 1
map_varchar2.count: 0
array_varchar2.count: 1
array_varchar2.exists(12): noPL/SQL 过程已成功完成。
这是为什么呢,万思不得其解,求高手解答!!!
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*Plus 运行时,输出如下:
nestable_varchar2.count: 1
map_varchar2.count: 0
array_varchar2.count: 1
array_varchar2.exists(12): yes
exception found.在PL/SQL developer 里运行时,输出的结果是这样:
nestable_varchar2.count: 1
map_varchar2.count: 0
array_varchar2.count: 1
array_varchar2.exists(12): no
exception found.由输出结果看出,PL/SQL developer的输出结果是正确的,array_varchar2.exists(12)应该返回为false!而SQL*Plus的输出结果是错误的!这是为什么呢,这么奇怪的结果输出?如果将抛异常的代码
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);注释掉,SQL*Plus的输出又正常了!
nestable_varchar2.count: 1
map_varchar2.count: 0
array_varchar2.count: 1
array_varchar2.exists(12): noPL/SQL 过程已成功完成。
这是为什么呢,万思不得其解,求高手解答!!!
解决方案 »
- ORA-12545: 因目标主机或对象不存在,连接失败
- 刚刚学oracle 9i各位大虾~~介绍基本好书!
- plsql下面 没有connect as选择项
- 想学pro*c 谁能给我讲讲从编写源码到编译再到执行的整个过程?
- 急救!!我的oracle今天突然进不去了,怎么解决阿~~~~在线等
- exp/imp, snatshop在oracle online文档的那个地方?
- 可不可以用vc程序动态创建oracle数据库?怎么做?
- 新手初次安装Oracle 9i错误提示:环境变量path字符超过1023字节,无法设置该值?
- 求一sql语句
- 数据库备份,表倒出!急。
- select-from-where(约束条件为空的问题)
- ORA-00918 未明确定义列
dbms_output.put_line('=='||array_varchar2(1));
执行与否,结果也不一致,是否sql*plus的机制与众不同?
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): yesPL/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): noPL/SQL 过程已成功完成。
PL/SQL块同样是以数据库对象为操作对象,但由于SQL本身不具备过程控制功能,所以为了能够与其他语言一样具备过程控制的处理功能,在SQL中加入诸如循环和选择等面向过程的处理功能,由此形成了PL/SQL。所有PL/SQL语句的解释均由PL/SQL引擎来完成,使用PL/SQL块可编写过程,触发器和包等数据库永久对象。SQL*Plus命令主要用来格式化查询结果,设置选择,编辑以及存储SQL命令,设置查询结果的显示格式,并且可以设置环境选项。可以编辑交互语句,可以与数据库进行“对话”。
--木有发现你的情况
[SYS@myoracle] SQL>startup
ORACLE 例程已经启动。Total System Global Area 293601280 bytes
Fixed Size 1248600 bytes
Variable Size 88081064 bytes
Database Buffers 197132288 bytes
Redo Buffers 7139328 bytes
数据库装载完毕。
数据库已经打开。
[SYS@myoracle] SQL>set serveroutput on
[SYS@myoracle] 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): noPL/SQL 过程已成功完成。[SYS@myoracle] 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): noPL/SQL 过程已成功完成。[SYS@myoracle] SQL>
exception
when others then
dbms_output.put_line('exception found.');里面'exception found.'的内容换成长点的字符或短点的字符,都可能会影响结果的输出!崩溃啊!
Connected as system
SQL> set serveroutput on;
SQL> @F:\oracletest\诡异的错误exists不确定性.sql
42 /
nestable_varchar2.count: 1
map_varchar2.count: 0
array_varchar2.count: 1
array_varchar2.exists(12): yes
PL/SQL procedure successfully completed
SQL> @F:\oracletest\诡异的错误exists不确定性.sql
42
43 /
nestable_varchar2.count: 1
map_varchar2.count: 0
array_varchar2.count: 1
array_varchar2.exists(12): yes
PL/SQL procedure successfully completed
SQL> @F:\oracletest\诡异的错误exists不确定性.sql
42
43
44
45 /
nestable_varchar2.count: 1
map_varchar2.count: 0
array_varchar2.count: 1
array_varchar2.exists(12): no
PL/SQL procedure successfully completed
SQL>
其中,F:\oracletest\诡异的错误exists不确定性.sql就是上面的那段代码。
--我的数据库就是10.2.0.1.0 没有发现你说的问题
[SYS@myoracle] SQL>select * from v$version;BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production[SYS@myoracle] SQL>