如果穷举也是可以的,只是比较麻烦的
create or replace view v_test as 
select name,type,num from dept a,
(
select * from t_1
union
select * from t_2
union 
select * from t_3
...
)  b
  where a.id=b.type

解决方案 »

  1.   

    但是(
    select * from t_1
    union
    select * from t_2
    union 
    select * from t_3
    ...
    )这样写也是静态的把表写出来,如果我再建多一个部门,那这视图就不对了,要重新写过
      

  2.   

    是啊,这个没有办法了,因为表是不能动态生成的呀
    要么你就用一个Sql来生成这样的sql来进行动态创建

    select 'create or replace view v_test as select name,type,num from dept a,( ' from dual;
    union
    select 'select * from '||tables ||' union ' as unionsql from dept;
    union
    select ') b where a.id=b.type' from dual;在你加入这个表时动态维护这个视图的更新就可以了(让系统动态维护视图也算上自动了,只是不太方便而已了),其他的也没有办法了!
      

  3.   

    不知道你用的什么平台,比如你用linux,你就crontab一个脚本,定期create or replace view。