2015-05-29 72 views
1
SELECT * 
FROM table1 
JOIN table2 ON table1.mycolumn = table2.mycolumn 

table1.mycolumn类型为Number(10)table2.mycolumn类型为Number(6)。如果没有Oracle抛出错误,我能做些什么来加入它们?对数列加入不同大小

+0

我的意思是,不执行该改变数据定义 – Ferenjito

+1

就加入他们的操作,还有什么是你需要做的。 –

+1

我期待@ughai正在谈论'CAST()',如:CAST(table2.mycolumn number(10))'。除了我认为在这种情况下它是无关紧要的。假设'table1.mycolumn = table2.column'是一个错字,而你的意思是'table1.mycolumn = table2.mycolumn',那就是。 – Boneist

回答

1

为什么你认为你会得到一个错误?你试过了吗?

create table t1 (col1 number(10)); 

create table t2 (col1 number(6)); 

insert into t1 
select 1000000001 col1 from dual union all 
select 1111111 col1 from dual union all 
select 1 col1 from dual; 

insert into t2 
select 111111 col1 from dual union all 
select 1 col1 from dual; 

commit; 

select * 
from t1 inner join t2 on (t1.col1 = t2.col1); 

     COL1  COL1_1 
---------- ---------- 
     1   1 
3

没有错误这样做:

SQL Fiddle

的Oracle 11g R2架构设置

CREATE TABLE table_a (
    num_a NUMBER(6) 
); 

CREATE TABLE table_b (
    num_b NUMBER(10) 
); 

INSERT INTO table_a VALUES (123456); 
INSERT INTO table_b VALUES (123456); 
INSERT INTO table_b VALUES (1234567890); 

查询1

select * 
from table_a a 
    join table_b b 
    on a.num_a = b.num_b 

Results

| NUM_A | NUM_B | 
|--------|--------| 
| 123456 | 123456 |