ORACLE MAX对CHAR类型的特殊处理(V10.2.0.1.0)
2014-01-16 22:20
357 查看
ORACLE使用MAX函数处理CHAR类型【指CHAR(1)类型】时,将其返回值INTO到某变量【变量类型也为CHAR(1)类型】,运行时会报错,需要使用字符处理函数对MAX返回值进行处理(例如TO_CHAR,NVL函数)或将变量类型设置为VARCHAR2(4000)【如果将变量类型设置为VARCHAR2(3999),运行时也会报错】,才能正常运行。 下面查询公司最高职位类型为例进行分析。
建立职位信息表(position),脚本如下:
准备数据,脚本如下:
在Command窗口下进行测试,直接赋值的测试脚本如下:
以上脚本会产生如下错误:
ORA-06502: PL/SQL: 数字或值错误 : 字符串缓冲区太小
ORA-06512: 在 line 6
将查询position_type最大值改成如下语句:
则能正常运行,运行结果如下:
MOST POSITION IS:2-高级软件工程师
PL/SQL procedure successfully completed
建立职位信息表(position),脚本如下:
-- Create table position_type:职位类别 position_name:职位名称 create table position ( position_type char(1) default ' ' not null, position_name varchar2(40) default ' ' not null ) ; -- Create indexes create unique index idx_position on position (position_type);
准备数据,脚本如下:
insert into position(position_type, position_name) values('0', '初级软件工程师'); insert into position(position_type, position_name) values('1', '中级软件工程师'); insert into position(position_type, position_name) values('2', '高级软件工程师');
在Command窗口下进行测试,直接赋值的测试脚本如下:
set serveroutput on declare v_position_type char(1); v_position_name varchar2(40); begin select max(position_type) into v_position_type from position; if trim(v_position_type) is not null then select position_name into v_position_name from position where position_type = v_position_type; end if; DBMS_OUTPUT.PUT_LINE('MOST POSITION IS:'||v_position_type||'-'||v_position_name); end; /
以上脚本会产生如下错误:
ORA-06502: PL/SQL: 数字或值错误 : 字符串缓冲区太小
ORA-06512: 在 line 6
将查询position_type最大值改成如下语句:
select nvl(max(position_type), ' ') into v_position_type from position;
则能正常运行,运行结果如下:
MOST POSITION IS:2-高级软件工程师
PL/SQL procedure successfully completed
相关文章推荐
- 处理Oracle XMLType字段类型不兼容的特殊字符
- oracle的char类型对空格的怪异处理
- Oracle中对number类型数据to_char()出现各位少0,或者值为###的处理
- Oracle bug 使用max或min函数into到一个char类型报字符缓冲区太小的错误
- oracle的char类型对空格的怪异处理
- C 使用 int 类型来处理字符常量,而不是 char 类型
- oracle中的数据类型char
- Oracle中Clob类型处理解析:ORA-01461:仅可以插入LONG列的LONG值赋值
- Biztalk-Web Service集成对消息Xsd值类型节点的特殊处理
- 运用C#处理lob数据类型 (Oracle)
- oracle --date-对应 mysql 时间类型的以及空值的处理
- ORACLE中date类型字段的处理
- 1. Oracle内置数据类型--字符串, 2. char的大小和字符集有关
- 在Oracle中CHAR,NCHAR,VARCHAR,VARCHAR2,NVARCHAR2这五种类型的区别
- 运用C#处理lob数据类型 (Oracle)
- [原创]在Oracle 10g,Number、Char和Varchar2类型作为主键,查询效率分析
- x86的cpu处理int类型并不是处理char高效多少
- Oracle CHAR,VARCHAR,VARCHAR2,nvarchar类型的区别与使用 .
- oracle数据导入导出-exp密码带特殊字符的处理
- NHibernate 处理 oracle 的long数据类型(ORA-01461: 仅能绑定要插入 LONG 列的 LONG 值)