码迷,mamicode.com
首页 > 数据库 > 详细

oracle视图建主键

时间:2014-07-12 17:58:56      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:视图主键

一个项目要求视图建主键,下面是一个例子

CREATE or replace VIEW SME_V_A....  (AGENTID,AGENTNAME,BUSYNUM,RESTNUM,RESTTIME,DEVICENONUM,DEVICENOSUM
      ,CONSTRAINT AGENTSTATIC_PK PRIMARY KEY (AGENTID) RELY DISABLE NOVALIDATE)
AS
SELECT A.AGENTID as AGENTID, ---座席编号
       (SELECT B.OPERATOR_NAME
          FROM CC_AGENT_INFO B
         WHERE B.WORK_NO = A.AGENTID) AS AGENTNAME, ----坐席姓名
       NVL(SUM(C.BUSYNUM), 0) AS BUSYNUM, -----示忙次数
       NVL(SUM(C.RESTNUM), 0) AS RESTNUM, ------休息次数
       NVL(SUM(C.RESTTIME), 0) AS RESTTIME, ------休息时长(分钟)
       NVL(D.DEVICENO_NUM, 0) AS DEVICENONUM, -------接话总量
       NVL(D.DEVICENO_SUM, 0) AS DEVICENOSUM-------接话总时长
  FROM CC_V_.....   A
  LEFT JOIN 。。。。。。
  LEFT JOIN 。。。。。。
  GROUP BY A.AGENTID, D.DEVICENO_NUM, D.DEVICENO_SUM;

 

 查看是否已经存在主键

select a.constraint_name, a.column_name
  from user_cons_columns a, user_constraints b
 where a.constraint_name = b.constraint_name
   and b.constraint_type = 'P'
   and a.table_name = 'SME_V_A....'


 

oracle视图建主键,布布扣,bubuko.com

oracle视图建主键

标签:视图主键

原文地址:http://blog.csdn.net/myfmyfmyfmyf/article/details/37694731

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!