• oracle 创建学生选课视图


    1,视图概念:视图是一个逻辑结构,本身不包含任何数据,是一个可命名的select语句。
       透过视图可以看到底层数据,但是视图和数据是相互独立的。
    2,创建视图需要有DBA权限。
    3,语法:CREATE [OR REPLACE] [FORCE|NOFORCE] VIEW view[(alias[,alias]..)]
       AS subquery;
    4,create or replace 表示若视图存在则替换掉;
    如:
    SQL> create view testview3
      2  as 
      3  select * from test3;
    视图已创建。
     
    SQL> create view testview3
      2  as 
      3  select * from test3;
    create view testview3
                *
    第 1 行出现错误:
    ORA-00955: 名称已由现有对象使用

    修改视图:
    SQL> create or replace view testview3
      2  as
      3  select * from test3;
    视图已创建。
    5,force 表示若表不存在则强制创建视图;
    如:SQL> create view tt
      2  as
      3  select * from tt;
    create view tt
                *
    第 1 行出现错误:
    ORA-01731: 出现循环的视图定义

    SQL> create force view tt
      2  as
      3  select * from tt;
    警告: 创建的视图带有编译错误。
    6,查看视图结构:
    SQL> desc testview3;
     名称                                      是否为空? 类型
     ----------------------------------------- -------- ----------------------------
     ID                                        NOT NULL NUMBER(38)
     LNAME                                              VARCHAR2(20)
     FNAME                                              VARCHAR2(20)

    7,在使用聚合函数创建视图时,需制定别名;
    SQL> create view testview4
      2  as 
      3  select id,sum(id) from test3
      4  group by id;
    select id,sum(id) from test3
              *
    第 3 行出现错误:
    ORA-00998: 必须使用列别名命名此表达式

    SQL> create view testview4
      2  as
      3  select id,sum(id) test3_id from test3
      4  group by id;
    视图已创建。
     
    8,更新视图:
    SQL> select * from testview5;
      TEST5_ID TEST5_NAME           TEST5_FNAME
    ---------- -------------------- --------------------
             3 kong                 sales
             2 hh
    SQL> update testview5 set test5_name='kong_gai'
      2  where test5_id=3;
    已更新 1 行。
    SQL> select * from testview5;
      TEST5_ID TEST5_NAME           TEST5_FNAME
    ---------- -------------------- --------------------
             3 kong_gai             sales
             2 hh
     
    原文链接
  • 相关阅读:
    年末反思
    Flink运行时架构
    Phoenix 启动报错:Error: ERROR 726 (43M10): Inconsistent namespace mapping properties. Cannot initiate connection as SYSTEM:CATALOG is found but client does not have phoenix.schema.
    Clickhouse学习
    Flink简单认识
    IDEA无法pull代码到本地,Can't Update No tracked branch configured for branch master or the branch doesn't exist.
    第1章 计算机系统漫游
    简单的 Shell 脚本入门教程
    开源≠免费 常见开源协议介绍
    MySQL 视图
  • 原文地址:https://www.cnblogs.com/sunny3158/p/11315981.html
Copyright © 2020-2023  润新知