Oracle SQL中的“缺少右括号”

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle SQL中的“缺少右括号”相关的知识,希望对你有一定的参考价值。

我已经上传了所有代码。我认为我正在使用Oracle SQL Developer,这不是我所假设的正确方法吗?

用于大学作业。

--CREATESCRIPTS

CREATE TABLE Bug --Creating the bug table.
(
Bug_ID  VARCHAR2 (6)NOT NULL,
Bug_Name VARCHAR2 (100)NOT NULL,
Bug_Desc VARCHAR2 (255)NOT NULL,
Found_Date DATE NOT NULL,
CONSTRAINT PK_Bug PRIMARY KEY (Bug_ID) --creating the primary key for Bug. 

);

CREATE TABLE Engineer --Creating the engineer table. 
 (
Engineer_ID VARCHAR2(6)NOT NULL,
Engineer_First VARCHAR2 (12)NOT NULL,
Engineer_Last VARCHAR2 (12)NOT NULL,
CONSTRAINT PK_Engineer PRIMARY KEY(Engineer_ID)

);

COMMIT;

CREATE TABLE Project --Creating the project table. 
(
Project_ID VARCHAR2 (8)NOT NULL,
Project_Name VARCHAR2(10)NOT NULL,
CONSTRAINT PK_Project PRIMARY KEY (Project_ID)

);

COMMIT;

CREATE TABLE Note --Creating the note table. 
(
Note_ID VARCHAR2(4) NOT NULL,
note_name VARCHAR2 (4)NOT NULL,
Note_Hours spent HOUR(4)NOT NULL,
Note_content VARCHAR2(254)NOT NULL,
Engineer_ID VARCHAR2(6)NOT NULL,
Bug_ID VARCHAR2(6)NOT NULL,
CONSTRAINT PK_Note PRIMARY KEY (Note_ID),
CONSTRAINT FK_BugNoteID FOREIGN KEY(bug_ID) REFERENCES Bug(Bug_ID),
CONSTRAINT FK_NoteEngineerID FOREIGN KEY(Engineer_ID) REFERENCES Engineer (Engineer_ID)

);

COMMIT;

CREATE TABLE Project_bug --Creating the Project bug table. 
(
Bug_ID VARCHAR2(6),
Project_ID VARCHAR2(8),
CONSTRAINT FK_bug_project_bugID FOREIGN KEY (Bug_ID) REFERENCES bug (bug_ID),
CONSTRAINT FK_bug_project_projectID FOREIGN KEY (Project_ID) REFERENCES Project (Project_ID),
CONSTRAINT PK_Bug_Project PRIMARY KEY (Bug_ID, Project_ID),

);

COMMIT;

CREATE TABLE Allocation_fix--creating the allocation fix table. 
(
Engineer_ID VARCHAR2(6),
Bug_ID VARCHAR2(6),
CONSTRAINT FK_Engineer_FixAllocatedID FOREIGN KEY (Engineer_ID) REFERENCES Engineer (Engineer_ID),
CONSTRAINT FK_Bug_FixAllocatedID FOREIGN KEY (Bug_ID) REFERENCES Bug (Bug_ID),
CONSTRAINT PK_Fix_Allocation PRIMARY KEY (Bug_ID, Engineer_ID)

);

COMMIT;


CREATE TABLE Allocation_test --creating the allocation test table.
( 
Engineer_ID VARCHAR2(6),
bug_ID VARCHAR2 (8),
CONSTRAINT FK_Engineer_TestAllocatedID FOREIGN KEY (Engineer_ID) REFERENCES Engineer (Engineer_ID),
CONSTRAINT FK_Bug_TestAllocatedID FOREIGN KEY (Bug_ID) REFERENCES Bug (Bug_ID),
CONSTRAINT PK_Test_Allocation PRIMARY KEY (Bug_ID, Engineer_ID)

);

COMMIT;


--INSERT SCRIPTS

INSERT INTO bug VALUES ('B1','bug_1','first bug','6-DEC-98')
INSERT INTO bug VALUES ('B2','bug_2','second bug','7-DEC-98')
INSERT INTO bug VALUES ('B3','bug_3','third bug','8-DEC-98')
INSERT INTO bug VALUES ('B4','bug_4','fourth bug','9-DEC-98')
INSERT INTO bug VALUES ('B5','bug_5','fifth bug','10-DEC-98')
INSERT INTO bug VALUES ('B6','bug_6','sixth bug','11-DEC-98')


COMMIT;

INSERT INTO Engineer VALUES ('E1','Jones','Lee') --tester
INSERT INTO Engineer VALUES ('E2','Friend','Kane') --fixer
INSERT INTO Engineer VALUES ('E3','Ingham','Darcie') --tester
INSERT INTO Engineer VALUES ('E4','Jones','Carly') --fixer
INSERT INTO Engineer VALUES ('E5','Evergreen','Damien') --tester
INSERT INTO Engineer VALUES ('E6', 'Danes', 'Lucy') --showing the optionality of having an engineer that isnt a tester or a fixer

COMMIT;

INSERT INTO Note VALUES ('N1','Test1','4','testing was carried out by E1')
INSERT INTO Note VALUES ('N2','Fix1','5','fix was applied by E2')
INSERT INTO Note VALUES ('N3','Test2','7','testing was carried out by E1') 
INSERT INTO Note VALUES ('N4','Fix2','3','fix was applied by E3')
INSERT INTO Note VALUES ('N5','Test3','3','testing was carried out by E4')
INSERT INTO Note VALUES ('N6','Fix3','1','fix was applied by E5')
INSERT INTO Note VALUES ('N7','Test4','5','testing was carries out by E4') 
INSERT INTO Note VALUES ('N8','Fix4','9','fix was applied by E5')

COMMIT;

INSERT INTO project VALUES ('P1', 'Bethesda')
INSERT INTO project VALUES ('P2', 'Activsion')
INSERT INTO project VALUES ('P3', 'Valve')
INSERT INTO project VALUES ('P4', 'Mojang')
INSERT INTO project VALUES ('P5', 'Blizzard')
INSERT INTO project VALUES ('P6', 'Rockstar')

COMMIT;

INSERT INTO Project_bug VALUES ('B1', 'P1')
INSERT INTO Project_bug VALUES ('B2', 'P2')
INSERT INTO Project_bug VALUES ('B3', 'P3')
INSERT INTO Project_bug VALUES ('B4', 'P4')
INSERT INTO Project_bug VALUES ('B5', 'P5')
INSERT INTO Project_bug VALUES ('B6', 'P6')

COMMIT;

INSERT INTO Allocation_fix VALUES ('E1','B1' ) --this data set shows the optionality of engineers being "fixers" or "testers"
INSERT INTO Allocation_fix VALUES ('E2','B2')
INSERT INTO Allocation_fix VALUES ('E3','B3')
INSERT INTO Allocation_fix VALUES ('E4','B4')
INSERT INTO Allocation_fix VALUES ('E5','B5')
INSERT INTO Allocation_fix VALUES ('E1','B6')


COMMIT;

INSERT INTO Allocation_test VALUES ('E1','B1') -- this data set shows the optionality of engineers being "fixers" or "testers"
INSERT INTO Allocation_test VALUES ('E2','B2')
INSERT INTO Allocation_test VALUES ('E3','B3')
INSERT INTO Allocation_test VALUES ('E4','B4')
INSERT INTO Allocation_test VALUES ('E5','B5')
INSERT INTO Allocation_test VALUES ('E1','B6')

COMMIT;

--SELECT SCRIPTS

-- 1: List of all the bugs, and their details.

 SELECT*From bug;

-- Query 2 : List of all bugs, and their notes. 

 SELECT bug_type, note_id, note_content
 FROM bug,note 
 WHERE bug.bug_id=note.bug_id;

 -- Query 3 : List of all bugs, with their notes, and the engineers who have written them; sorted by name of engineer.

 SELECT bug.bug_id,bug_type, note_id, note_content, engineer.engineer_id, engineer_firstname, engineer_lastname
 FROM bug, note, engineer
 WHERE bug.bug_id=note.bug_id AND note.engineer_id=engineer.engineer_id
 ORDER BY engineer_lastname ASC;

 --Query 4: List the bugs and how much cumulative time (in hours) they have taken; ordered by time taken.

 SELECT bug.bug_id, SUM(note.hours_spent) 
 FROM note,bug
 WHERE bug.bug_id=note.bug_id
 GROUP BY bug.bug_id
 ORDER BY SUM(note.hours_spent) ASC;

  --Query 5 : The bug that has taken most time to fix and the projects it is connected to.

SELECT bug_taken_most_time_to_fix.bug_id, bug_project.project_id, bug_taken_most_time_to_fix."Total_Hours" FROM
(
      SELECT bug.bug_id, SUM(note.hours_spent) AS "Total_Hours"
  FROM note,bug
    WHERE bug.bug_id=note.bug_id
    GROUP BY bug.bug_id
    ORDER BY SUM(note.hours_spent) DESC FETCH FIRST ROW ONLY
)
bug_taken_most_time_to_fix, bug_project
WHERE bug_taken_most_time_to_fix.bug_id = bug_project.bug_id; 

--DROP SCRIPTS

DROP TABLE allocation_test;
DROP TABLE allocation_fix;
DROP TABLE Project_bug;
DROP TABLE Note;
DROP TABLE Engineer;
DROP TABLE Bug;

COMMIT;
答案

注释表的CREATE表语法中存在语法错误。 -

CREATE TABLE Note --Creating the note table. 
(
Note_ID VARCHAR2(4) NOT NULL,
note_name VARCHAR2 (4)NOT NULL,
Note_Hours_spent NUMBER(4)NOT NULL,
Note_content VARCHAR2(254)NOT NULL,
Engineer_ID VARCHAR2(6)NOT NULL,
Bug_ID VARCHAR2(6)NOT NULL,
CONSTRAINT PK_Note PRIMARY KEY (Note_ID),
CONSTRAINT FK_BugNoteID FOREIGN KEY(bug_ID) REFERENCES Bug(Bug_ID),
CONSTRAINT FK_NoteEngineerID FOREIGN KEY(Engineer_ID) REFERENCES Engineer (Engineer_ID)
);

并且在Project_bug表的最后有一个逗号-

CREATE TABLE Project_bug --Creating the Project bug table. 
(
Bug_ID VARCHAR2(6),
Project_ID VARCHAR2(8),
CONSTRAINT FK_bug_project_bugID FOREIGN KEY (Bug_ID) REFERENCES bug (bug_ID),
CONSTRAINT FK_bug_project_projectID FOREIGN KEY (Project_ID) REFERENCES Project (Project_ID),
CONSTRAINT PK_Bug_Project PRIMARY KEY (Bug_ID, Project_ID)
);

由于您没有足够的值插入到该表中,所以最后一次将您的插入语句插入到笔记表中时,this提琴出现了错误。

以上是关于Oracle SQL中的“缺少右括号”的主要内容,如果未能解决你的问题,请参考以下文章

SQL Oracle 命令“缺少右括号”

Oracle Live SQL:ORA-00907:缺少右括号 -

ORACLE SQL 错误 - 缺少右括号 - 查询 [关闭]

Oracle SQL - 奇怪的“ORA-00907 缺少右括号”错误

在Oracle sql live上运行时缺少右括号[关闭]

在 oracle SQL 中使用 insrt 函数遇到“ORA-00907:缺少右括号”