5

Hi trying to create a view in oracle. However I'm getting errors in my code which I can't work out how to solve. Currently I'm trying to create a view which shows Managers, their first and last name the clinic they are assigned too The PK of the clinic and the FK of the address of the clinic All addresses are stored in that table (yes I know it's not standard but it's how I am choosing to do it) So I also want to show the address details of the clinic which they work at

Of course this include two WHERE statements which I am unsure how to implement The first is where STAFFJOBNAME "MANAGER"

and the second is where the ADDRESSNO matches on both tables

CREATE VIEW MANAGER AS
    SELECT STAFF.staffno,STAFF.staffFirstName,STAFF.staffLastName,CLINIC.clinicNo, CLINIC.addressNo
    FROM STAFF,CLINIC
    WHERE addressNo = 
    (
        SELECT addressNo, addressStreet, addressCity, addressCounty, addressPostcode, addressTelephone,
        FROM ADDRESS,
        INNER JOIN CLINIC,
        ON ADDRESS.addressNo = CLINIC.addressNo
    ) AND STAFF.staffJobName = 'MANAGER';

I also have this version. So I'm not sure which is more closer to the correct one.

CREATE VIEW MANAGER
(
    AS
    SELECT STAFF.staffno,STAFF.staffFirstName,STAFF.staffLastName,CLINIC.clinicNo, CLINIC.addressNo, ADDRESS.addressNo, ADDRESS.addressStreet, ADDRESS.addressCity, ADDRESS.addressCounty, ADDRESS.addressPostcode, ADDRESS.addressTelephone,
    FROM ADDRESS, STAFF,
    INNER JOIN CLINIC,
    ON ADDRESS.addressNo = CLINIC.addressNo
);
3
  • does the query in the first example even run? Commented Mar 18, 2014 at 21:06
  • Trying to create the first view MANAGER will throw ORA-00913: too many values. Commented Mar 18, 2014 at 21:52
  • Your second version has a few issues - you can't have ( and ) surrounding the definition of the view, and you have too many trailing commas (,). Commented Mar 19, 2014 at 3:44

2 Answers 2

10
CREATE VIEW MANAGERANDCLINIC    AS
    SELECT STAFF.staffno,STAFF.staffFirstName,STAFF.staffLastName,CLINIC.clinicNo, ADDRESS.addressStreet, ADDRESS.addressCity, ADDRESS.addressCounty, ADDRESS.addressPostcode, ADDRESS.addressTelephone
    FROM STAFF,CLINIC, ADDRESS
    WHERE (CLINIC.CLINICMANAGERNO = STAFF.STAFFNO) AND
    (CLINIC.ADDRESSNO = ADDRESS.ADDRESSNO)
    ORDER BY CLINIC.CLINICNO;

Eventually found the answer to my own question

Sign up to request clarification or add additional context in comments.

Comments

0

You are getting too many values error for your first view because in your inner query you are returning many columns but in the where clause you have only one column.

Also in your second code please alter like below

 CREATE VIEW MANAGER

AS
SELECT STAFF.staffno,STAFF.staffFirstName,STAFF.staffLastName,CLINIC.clinicNo, CLINIC.addressNo, ADDRESS.addressNo, ADDRESS.addressStreet, ADDRESS.addressCity, ADDRESS.addressCounty, ADDRESS.addressPostcode, ADDRESS.addressTelephone,
FROM ADDRESS, STAFF
INNER JOIN CLINIC
ON ADDRESS.addressNo = CLINIC.addressNo;

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.