Oracle View-built primary key

Source: Internet
Author: User

A project requires a view to build a primary key, here's an example

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,---seat number
(SELECT B.operator_name
From Cc_agent_info B
where b.work_no = A.agentid) as AgentName,----agent Name
NVL (SUM (C.busynum), 0) as Busynum,-----show busy times
NVL (SUM (C.restnum), 0) as Restnum,------number of breaks
NVL (SUM (C.resttime), 0) as resttime,------length of rest (minutes)
NVL (d.deviceno_num, 0) as Devicenonum,-------total number of words received
NVL (d.deviceno_sum, 0) as devicenosum-------total length of conversation
From Cc_v_ ..... A
Left JOIN ...
Left JOIN ...
GROUP by A.agentid, D.deviceno_num, d.deviceno_sum;

To see if a primary key already exists

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 .... '


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.