现在有3张表,表结构是相同的,我想把3张表写成一个视图,请问高手,如何编写,小弟视图不太会写

解决方案 »

  1.   

    --格式
    create or replace view view_name
    as
    select * from table1;
      

  2.   

    假如为table1,table2,table3,如何去写?
      

  3.   

    create or replace view view_name
    as
    select * from table1
    union all
    select * from table2
    union all
    select * from table3
      

  4.   

    你要从这三个表里的得到什么数据咯?
    是union 还是3个表进行关联
      

  5.   


    create or replace view view_name
    as
    select * from table1
    union all
    select * from table2
    union all
    select * from table3;
      

  6.   

    按照你们写的,会报错,错误信息是ORA-01789: query block has incorrect number of result columns
      

  7.   

    我知道哪错了,谢谢啊,我想问一下,如果三个表做成一个表的查询速度快(建立索引),还是三张表做成一个视图查询的速度快,还有就是union与union all有什么不同吗?
      

  8.   

    视图对查询速度没有什么提高 
    只是简化了查询语句union 会去重复 union all 不会
    如果你的两个查询结果不可能重复的话 建议用union all 
      

  9.   


    视图只能简化查询,不能增加查询速度
    UNION 去重再排序
    UNION ALL 不去重不排序  效率高