我有A,B,C三张表,用union连接
为了区分不同表的记录,我增加了一个字段tableType,
A表记录为1
B表记录为2
C表记录为3我做了一个视图把三张表连接以后,我用SQL语句查询,使用where tableType=1时不能过滤数据,还是出来所有数据。各位,有遇到过这样的情况吗?我用的是ORACLE数据库。

解决方案 »

  1.   

    Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production,没有问题SQL> create table a1(cname nvarchar2(20));Table createdExecuted in 0.015 secondsSQL> create table a2(cname nvarchar2(20));Table createdExecuted in 0.016 secondsSQL> create table a3(cname nvarchar2(20));Table createdExecuted in 0 secondsSQL> insert into a1 select 'a' from dual;1 row insertedExecuted in 0 secondsSQL> insert into a2 select 'b' from dual;1 row insertedExecuted in 0 secondsSQL> insert into a3 select 'c' from dual;1 row insertedExecuted in 0 secondsSQL> create or replace view test_view
      2  as
      3    select cname,1 as tabletype from a1
      4    union all
      5    select cname,2 as tabletype from a2
      6    union all
      7    select cname,3 as tabletype from a3;View createdExecuted in 0 secondsSQL> select * from test_view;CNAME                                     TABLETYPE
    ---------------------------------------- ----------
    a                                                 1
    b                                                 2
    c                                                 3Executed in 0.016 secondsSQL> select * from test_view where tabletype=1;CNAME                                     TABLETYPE
    ---------------------------------------- ----------
    a                                                 1Executed in 0 seconds