sunny123456

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  1796 随笔 :: 22 文章 :: 24 评论 :: 226万 阅读
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
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
 
原文链接
posted on   sunny123456  阅读(510)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示