SQLSERVER 和 ORACLE 创建视图

Posted 997icu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQLSERVER 和 ORACLE 创建视图相关的知识,希望对你有一定的参考价值。

SQLSERVER

if exists(select * from sysobjects where id=OBJECT_ID(N‘VW_SZYD_YTCT‘) and objectproperty(id,N‘IsView‘)=1)
drop view VW_SZYD_YTCT --删除视图
go
create view VW_SZYD_YTCT --创建视图
as
SELECT
K.SZYDHYB_NM AS HYNM,
K.SZYDHYB_TBDWBH AS TBDWBH,
K.SZYDHYB_TBDWMC AS TBDWMC,
K.SZYDHYB_HYBH AS HYBH,
K.SZYDHYB_HYLXMC AS HYLXMC,
K.SZYDHYB_HYMC AS HYMC,
K.SZYDHYB_HYSJ AS HYSJ,
K.SZYDHYB_SBZT AS SBZT,
L.SZYDYTB_NM AS YTNM,
L.SZYDYTB_YTMC AS YTMC,
L.SZYDYTB_YTBM AS YTBM,
L.SZYDYTB_LXRY AS LXRY,
L.SZYDYTB_SFTG AS SFTG,
L.SZYDYTB_SFXYDB AS SFXYDB,
L.SZYDYTB_YCQK AS YCQK,
Y.SZYDYTGLSXB_SXBH AS SXBH,
Z.SZYDSXB_LXMC AS LXMC
FROM SZYDYTB L
LEFT JOIN SZYDHYB K ON K.SZYDHYB_NM=L.SZYDYTB_GLNM
LEFT JOIN SZYDYTGLSXB Y ON L.SZYDYTB_NM=Y.SZYDYTGLSXB_GLNM
LEFT JOIN SZYDSXB Z ON Z.SZYDSXB_NM=Y.SZYDYTGLSXB_SXNM
go

 

ORACLE

 

CREATE OR REPLACE VIEW VW_SXGL_SXCX AS
SELECT
L.SXGLSXZXQK_PZNM AS PZNM,--品种内码
L.SXGLSXZXQK_PZBH AS PZBH,--品种编号
L.SXGLSXZXQK_PZMC AS PZMC,
L.SXGLSXZXQK_SSDWBH AS SSDWBH,
L.SXGLSXZXQK_SSDWMC AS SSDWMC,
L.SXGLSXZXQK_SXJGBH AS SXJGBH,
L.SXGLSXZXQK_SXJGMC AS SXJGMC,
K.SXGLSXXY_SXBZBH AS BZBH,
K.SXGLSXXY_SXBZMC AS BZMC,
SUM(L.SXGLSXZXQK_SXED) AS SXED,
SUM(L.SXGLSXZXQK_ZYED) AS ZYED,
SUM(L.SXGLSXZXQK_ZXED) AS ZXED,
SUM(L.SXGLSXZXQK_SFED) AS SFED
FROM SXGLSXZXQK L
LEFT JOIN SXGLSXXY K ON L.SXGLSXZXQK_PZBH=K.SXGLSXXY_XYBH
GROUP BY L.SXGLSXZXQK_PZNM,L.SXGLSXZXQK_PZBH,L.SXGLSXZXQK_PZMC,K.SXGLSXXY_SXBZBH,L.SXGLSXZXQK_SSDWBH,L.SXGLSXZXQK_SSDWMC,L.SXGLSXZXQK_SXJGBH,L.SXGLSXZXQK_SXJGMC,K.SXGLSXXY_SXBZMC;

以上是关于SQLSERVER 和 ORACLE 创建视图的主要内容,如果未能解决你的问题,请参考以下文章

oracle 视图sql语句怎么写

oracle 视图sql语句怎么写

Oracle重新获取统计信息以及SQLSERVER重建索引

oracle带参数的视图缺点

获取oracle视图SQL语句的工具

Oracle:修改 varchar 列大小后重新创建数据库视图