create table USERINFO2
(
USER_ID CHAR(32) not null,
USER_CODE VARCHAR2(32) not null,
PASSWORD CHAR(32) not null,
USER_NAME VARCHAR2(50) not null
);
insert into userinfo2 values('001','aaa','www','eee');
insert into userinfo2 values('002','bbb','vvv','sss');
1)Length长度区别
SQL> select length(user_id),length(user_code) from userinfo2;
3)char的自动转换
SQL> update userinfo2 set user_name='Good' where user_id='001';
1 row updated
SQL> select user_name from userinfo2 where user_id='001';
USER_NAME
--------------------------------------------------
Good
看到了吧,以上语句是在PL/SQL DEVELOPER上执行的,在sqlplus上执行也是一样的.
所以ORACLE sql引擎会把常量自动的理解为目标字段的类型来处理的,对于任何类型应该都是一样的.
反过来一个过程执行
declare
v_code char(3);
begin
v_code:='aaa';
update userinfo2 set user_name='Hapyy' where user_code=v_code;
commit;
end;
结果是会得到正确的修改,应为在这个例子中恰巧USER_CODE存在长度为3的,如果把V_CODE定义为CHAR(N) N>3,那么结果还是不会变化,因为没有匹配的条件存在.