加入不同大小的数字列

时间:2015-05-29 10:43:45

标签: sql oracle

SELECT * 
FROM table1 
JOIN table2 ON table1.mycolumn = table2.mycolumn

table1.mycolumn的类型为Number(10)table2.mycolumn的类型为Number(6)。如果没有Oracle抛出错误,我该怎么办呢?

2 个答案:

答案 0 :(得分: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 |

答案 1 :(得分: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