Oracle視圖的curd

來源:互聯網
上載者:User

1.使用create or replace view命令建立視圖

文法格式:

create or replace view 視圖名

as select 查詢子句

例子:

create or replace view  tb_user_view1 as select count(username) shuliang,username from tb_user group by username order by shuliang asc

2.使用create or replace view命令修改視圖

文法格式:

create or replace view 視圖名

as select 查詢子句

例子:

create or replace view tb_user_view1 as select * from tb_user where username='a'

3.使用drop view 命令刪除視圖

格式:

drop view 視圖名

例子:

drop view tb_user_view1

4.利用視圖操作基本表

---添加資料行(直接影響基本表)

insert into tb_user_view1 values(8,'insert',5)

---修改資料行(影響基本表)

update tb_user_view1 set username='update' where bh=3

---刪除資料行(直接影響基本表)

delete from tb_user_view1 where bh=2

多表關聯建立視圖

格式:CREATE OR REPLACE FORCE VIEW 視圖名(列表名1,列表名2,……,列表名n)as select  查詢子句

例子:

CREATE OR REPLACE FORCE VIEW  tb_username_address (bh, username, address_id, address) AS
  SELECT u.bh,u.username,a.bh,a.address FROM tb_user u,tb_address a WHERE  u.address_id=a.bh

修改視圖

格式:CREATE OR REPLACE FORCE VIEW 視圖名(列表名1,列表名2,……,列表名n)as select  查詢子句

例子:
CREATE OR REPLACE FORCE VIEW  tb_username_address (bh, username, address_id, address) AS
  SELECT u.bh,u.username,a.bh,a.address FROM tb_user u,tb_address a WHERE  u.address_id=a.bh and a.address='xinxiang'
drop view 命令刪除視圖

格式:

drop view 視圖名

例子:drop view tb_username_address

刪除資料行(影響基本表):

例子:delete tb_username_address where bh=5

視圖來自多個基本表時,不允許添加資料。

修改資料行(影響基本表):

例子:update tb_username_address set username='updaten' where bh=6

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.