create table test as select 'abcd' col from dual;
字段col数据类型默认为char(4)现在如果insert into test select 'abcdef' from dual; 会提示长度大如果insert into test select 'ab' from dual;可以插入
但select * from test where col='ab';
有时有数据,有时没有,可能是不同数据库对char类型设置的问题
特别是alter table test modify(col varchar2(20));后
select * from test where col='ab';就永远不行
而必须使用select * from test where col='ab '; varchar2和char对字符串末尾有空格 怎么有这个差别不想每次都用alter modify和update
能不能在建表时同时指定数据类型
字段col数据类型默认为char(4)现在如果insert into test select 'abcdef' from dual; 会提示长度大如果insert into test select 'ab' from dual;可以插入
但select * from test where col='ab';
有时有数据,有时没有,可能是不同数据库对char类型设置的问题
特别是alter table test modify(col varchar2(20));后
select * from test where col='ab';就永远不行
而必须使用select * from test where col='ab '; varchar2和char对字符串末尾有空格 怎么有这个差别不想每次都用alter modify和update
能不能在建表时同时指定数据类型
解决方案 »
- ORA-00604: 递归 SQL 级别 1 出现错误 ORA-01003: 语句未进行语法分析,救命啊!
- 如何在JSP程序里另起一个线程?
- 如何在oracle中实现跨行操作
- 求一个SQL,跟INDEX有关的
- 一个难题!这里有人能否帮忙解决?
- 新手请教!Oracle多表查询能不能使用inner join 语句?
- 在oracle能不能把Table中的两个字段xing 和 ming组合成一个字段显示出来!
- 为什么登陆sql plus时,显示协议适配器错误
- 关于oracle9i rollback segment的问题?(请高手帮忙)
- unix系统下面启动oracle的图形界面
- orcale
- oracle 中 lock table的问题
就是说有一个元表,然后再生成根据这个元表结构上一样(字段结构是一样的)表的时候用这种建表方式。
按楼主的要求,你先建表,然后再插入数据不就行了么?
必须alter table tbb modify col varchar2(n)
update tbb set col=replace(col,' ','')
char是定长的,定义时规定其长度N,插入数据时会用空格补位,就是说该字段上存储的数据长度都是N至于“不想每次都用alter modify和update”,如果你以“create table test as select ”方式建表,我觉得可能不能避免。
2 (id number(10),
3 name char(4));
Table created
SQL> insert into tab_char values(1,'1');
1 row inserted
SQL>
SQL> create table tab_char_bak
2 as
3 select id,rtrim(cast(name as varchar2(100))) name from tab_char;
Table created
SQL> select * from tab_char_bak where name='1';
ID NAME
----------- --------------------------------------------------------------------------------
1 1
SQL>
这样做的代价就是写create table as select 语句的时候比较麻烦.
Name Type Nullable Default Comments
---- ------------- -------- ------- --------
ID NUMBER(10) Y
NAME VARCHAR2(100) Y
SQL>
SQL> create table tbb as select cast(trim('111aa') as varchar2(10)) zf from dual
2 /
Table created
SQL> desc tbb
Name Type Nullable Default Comments
---- ------------ -------- ------- --------
ZF VARCHAR2(10) Y
SQL> select zf,length(zf) from tbb
2 /
ZF LENGTH(ZF)
---------- ----------
111aa 5
rtrim(cast(name as varchar2(100))) 就是要这个功能