473,385 Members | 1,934 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Create Primary Key on View

js
I am trying to create a primary key constraint on a view in the
following statement. However, I got an error ORA-00907: missing right
parenthesis. If the CONSTRAINT clause is removed, then the view is
created fine. Does anyone know how to creat Primary Key Constraint
for a View? Thanks.

CREATE OR REPLACE VIEW RPT_VW_WMN (
CARD, EC_D_CODE, EC_M_CODE,
START_DATE, PR_NAME, PR_ID, ELIG, ANNUALY, MONTHLY, PENDING,
/* ORA-00907: missing right parenthesis error here */
CONSTRAINT MyView_pk PRIMARY KEY
(CARD, EC_D_CODE, EC_M_CODE, START_DATE, PR_NAME, PR_ID )
)

AS
SELECT 'DUMMY' CARD, A.EC_D_CODE, A.EC_M_CODE,
TO_DATE(TO_CHAR(A.EC_DATETIME,'MONTH DD YYYY'),'MM/DD/YYYY')
- TO_CHAR(A.EC_DATETIME,'DD') +1 AS START_DATE,
C.PR_NAME, C.PR_ID,
COUNT(DISTINCT A.PNT_ID) AS ELIG,
SUM(CASE WHEN A.PNT_ID IN
(SELECT PNT FROM WOM WHERE APTDATE BETWEEN
ADD_MONTHS(A.EC_DATETIME -
TO_CHAR(A.EC_DATETIME,'DD')+1, -12) AND
A.EC_DATETIME - TO_CHAR(A.EC_DATETIME,'DD')+1)
THEN 1 ELSE 0 END) AS ANNUALY,
SUM(CASE WHEN A.PNT_ID IN
(SELECT PNT FROM WOM WHERE APPTDATE BETWEEN
A.EC_DATETIME - TO_CHAR(A.EC_DATETIME,'DD')+1 AND
ADD_MONTHS(A.EC_DATETIME -
TO_CHAR(A.EC_DATETIME,'DD')+1,1))
THEN 1 ELSE 0 END) AS MONTHLY,
SUM(CASE WHEN A.PNT_ID NOT IN
(SELECT PNTFROM WOM WHERE APPTDATE BETWEEN
ADD_MONTHS(A.EC_DATETIME -
TO_CHAR(A.EC_DATETIME,'DD')+1, -12) AND
ADD_MONTHS(A.EC_DATETIME -
TO_CHAR(A.EC_DATETIME,'DD')+1,1))
THEN 1 ELSE 0 END) AS PENDING
FROM EC A, PR C
WHERE A.EC_DATETIME BETWEEN A.EC_DATETIME -
TO_CHAR(A.EC_DATETIME,'DD')+1
AND ADD_MONTHS(A.EC_DATETIME - TO_CHAR(A.EC_DATETIME,'DD')+1, 1)
- 1
AND RTRIM(A.PR_ID_CODE) = C.PR_ID_CODE (+)
AND A.APT_STATUS_ID = 1
GROUP BY A.EC_D_CODE, A.EC_M_CODE,
TO_DATE(TO_CHAR(A.EC_DATETIME,'MONTH DD YYYY'),'MM/DD/YYYY')
- TO_CHAR(A.EC_DATETIME,'DD') +1 ,
C.PR_NAME, C.PR_ID

/************************************************** *****************************The
following is description from Oracle9i Application Developer's Guide -
Fundamentals Release 1 (9.0.1) for creating a view.
************************************************** *****************************/

CREATE [OR REPLACE] [[NO] FORCE] VIEW [schema .] view
[ ( { alias [column_constraint [column_constraint]...]
| table_or_view_constraint
}
[, { alias column_constraint [column_constraint]...
| table_or_view_constraint
}
]...
)
| object_view_clause
]
AS subquery [subquery_restriction_clause];

table_or_view_constraint::=
[CONSTRAINT constraint]
{ UNIQUE ( column [, column]... )
| PRIMARY KEY ( column [, column]... )
| FOREIGN KEY ( column [, column]... ) references_clause
| CHECK ( condition )
}
constraint_state

constraint_state::=
[ [[NOT] DEFERRABLE] [INITIALLY { IMMEDIATE | DEFERRED }]
| [INITIALLY { IMMEDIATE | DEFERRED }] [[NOT] DEFERRABLE]
]
[ RELY | NORELY ] [using_index_clause] [ ENABLE | DISABLE ]
[ VALIDATE | NOVALIDATE ] [exceptions_clause]
Jul 19 '05 #1
1 55900
Hi...
there are some restrictions on view constraints; "SQL Reference 9.2"
mentions:

/*
View Constraints
Oracle does not enforce view constraints. However, operations on views
are subject to the integrity constraints defined on the underlying
base tables. This means that you can enforce constraints on views
through constraints on base tables.

Restrictions on View Constraints
View constraints are a subset of table constraints and are subject to
the following restrictions:

You can specify only unique, primary key, and foreign key constraints
on views. However, you can define the view using the WITH CHECK OPTION
clause, which is equivalent to specifying a check constraint for the
view.
Because view constraints are not enforced directly, you cannot specify
INITIALLY DEFERRED or DEFERRABLE.
View constraints are supported only in DISABLE NOVALIDATE mode. You
must specify the keywords DISABLE NOVALIDATE when you declare the view
constraint, and you cannot specify any other mode.
You cannot specify the using_index_clause, the exceptions_clause
clause, or the ON DELETE clause of the references_clause.
You cannot define view constraints on attributes of an object column.
*/

So, you can try using this statement:

CREATE OR REPLACE VIEW RPT_VW_WMN (
CARD, EC_D_CODE, EC_M_CODE, START_DATE, PR_NAME, PR_ID, ELIG,
ANNUALY, MONTHLY, PENDING,
CONSTRAINT MyView_pk PRIMARY KEY
(CARD, EC_D_CODE, EC_M_CODE, START_DATE, PR_NAME, PR_ID) DISABLE
NOVALIDATE
)
AS
SELECT 'DUMMY' CARD, A.EC_D_CODE, A.EC_M_CODE,
etc...

Bye.

an********@yahoo.com (js) wrote in message news:<23**************************@posting.google. com>...
I am trying to create a primary key constraint on a view in the
following statement. However, I got an error ORA-00907: missing right
parenthesis. If the CONSTRAINT clause is removed, then the view is
created fine. Does anyone know how to creat Primary Key Constraint
for a View? Thanks.

CREATE OR REPLACE VIEW RPT_VW_WMN (
CARD, EC_D_CODE, EC_M_CODE,
START_DATE, PR_NAME, PR_ID, ELIG, ANNUALY, MONTHLY, PENDING,
/* ORA-00907: missing right parenthesis error here */
CONSTRAINT MyView_pk PRIMARY KEY
(CARD, EC_D_CODE, EC_M_CODE, START_DATE, PR_NAME, PR_ID )
)

AS
SELECT 'DUMMY' CARD, A.EC_D_CODE, A.EC_M_CODE,
TO_DATE(TO_CHAR(A.EC_DATETIME,'MONTH DD YYYY'),'MM/DD/YYYY')
- TO_CHAR(A.EC_DATETIME,'DD') +1 AS START_DATE,
C.PR_NAME, C.PR_ID,
COUNT(DISTINCT A.PNT_ID) AS ELIG,
SUM(CASE WHEN A.PNT_ID IN
(SELECT PNT FROM WOM WHERE APTDATE BETWEEN
ADD_MONTHS(A.EC_DATETIME -
TO_CHAR(A.EC_DATETIME,'DD')+1, -12) AND
A.EC_DATETIME - TO_CHAR(A.EC_DATETIME,'DD')+1)
THEN 1 ELSE 0 END) AS ANNUALY,
SUM(CASE WHEN A.PNT_ID IN
(SELECT PNT FROM WOM WHERE APPTDATE BETWEEN
A.EC_DATETIME - TO_CHAR(A.EC_DATETIME,'DD')+1 AND
ADD_MONTHS(A.EC_DATETIME -
TO_CHAR(A.EC_DATETIME,'DD')+1,1))
THEN 1 ELSE 0 END) AS MONTHLY,
SUM(CASE WHEN A.PNT_ID NOT IN
(SELECT PNTFROM WOM WHERE APPTDATE BETWEEN
ADD_MONTHS(A.EC_DATETIME -
TO_CHAR(A.EC_DATETIME,'DD')+1, -12) AND
ADD_MONTHS(A.EC_DATETIME -
TO_CHAR(A.EC_DATETIME,'DD')+1,1))
THEN 1 ELSE 0 END) AS PENDING
FROM EC A, PR C
WHERE A.EC_DATETIME BETWEEN A.EC_DATETIME -
TO_CHAR(A.EC_DATETIME,'DD')+1
AND ADD_MONTHS(A.EC_DATETIME - TO_CHAR(A.EC_DATETIME,'DD')+1, 1)
- 1
AND RTRIM(A.PR_ID_CODE) = C.PR_ID_CODE (+)
AND A.APT_STATUS_ID = 1
GROUP BY A.EC_D_CODE, A.EC_M_CODE,
TO_DATE(TO_CHAR(A.EC_DATETIME,'MONTH DD YYYY'),'MM/DD/YYYY')
- TO_CHAR(A.EC_DATETIME,'DD') +1 ,
C.PR_NAME, C.PR_ID

/************************************************** *****************************The
following is description from Oracle9i Application Developer's Guide -
Fundamentals Release 1 (9.0.1) for creating a view.
************************************************** *****************************/

CREATE [OR REPLACE] [[NO] FORCE] VIEW [schema .] view
[ ( { alias [column_constraint [column_constraint]...]
| table_or_view_constraint
}
[, { alias column_constraint [column_constraint]...
| table_or_view_constraint
}
]...
)
| object_view_clause
]
AS subquery [subquery_restriction_clause];

table_or_view_constraint::=
[CONSTRAINT constraint]
{ UNIQUE ( column [, column]... )
| PRIMARY KEY ( column [, column]... )
| FOREIGN KEY ( column [, column]... ) references_clause
| CHECK ( condition )
}
constraint_state

constraint_state::=
[ [[NOT] DEFERRABLE] [INITIALLY { IMMEDIATE | DEFERRED }]
| [INITIALLY { IMMEDIATE | DEFERRED }] [[NOT] DEFERRABLE]
]
[ RELY | NORELY ] [using_index_clause] [ ENABLE | DISABLE ]
[ VALIDATE | NOVALIDATE ] [exceptions_clause]

Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: M. Mehta | last post by:
It seems that you can not create a materialized view if you are using outer joins...can someone please verify this? Thanks M. Mehta Please follow my example below: created 2 tables:
2
by: Not Me | last post by:
Hi, Is it possible to create some SQL in VBA, 'run it' then view as a datasheet the results? I'm trying to throw together a fairly large search form, and VBA seems the best way to parse the...
7
by: sea | last post by:
Is it a good idea to programatically create a primary key? For example in a table called names, I have the following fields, (1) firstname (2)lastname (3) ID - will it be ok to create a primary...
0
by: qfchen | last post by:
Hi I'm using Visual Studio 2005 for database application. the database is MS access. I need to create a view in server explorer, when I right click on view folder, I can't see "Add New View" from...
1
by: NithyaJai | last post by:
Hai, I got a doubt on creating a view? Is that passible to create a view in MS Access 2000....... if so plz help me to do it... Thanks....
1
by: WayneW | last post by:
I need to create a view of tables in 2 databases. Is this possible?
0
by: rupinder03 | last post by:
I want to create tree view in data grid in vb.net 2005.can anyone tell me hw to create it................its urgent.......plz reply soon..............
1
by: js | last post by:
I am trying to create a primary key constraint on a view in the following statement. However, I got an error ORA-00907: missing right parenthesis. If the CONSTRAINT clause is removed, then the...
1
by: kensushi | last post by:
Hi, Im somewhat new to oracle SP writing. I need to do the following from the SP 1. execute the query 2. create a view and populate with the result of the above query 3 query that view and...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.