1

I am new to SQL and was trying to create a basic emp table to learn a bit. When I write the query and try to execute it, I keep getting the message "ORA-00907: missing right parenthesis". However I feel that I have included a pair of braces for each function. Could anyone please help me to figure out the issue and if possible could correct me if I am wrong??

Below is the sample

SQL> create table emp
  2  (emp id number(4),
  3  first name varchar2(25),
  4  last name varchar2(25),
  5  phone number number (10),
  6  department id number (4),
  7  job id number (4),
  8  salary number (6,2),
  9  commission_pct number (4,2),
 10  manager id number (4);
(emp id number (4),
        *
ERROR at line 2:
ORA-00907: missing right parenthesis
4

3 回答 3

6

您在第 2 行有一个开始括号;

(emp id number(4),
^

没有在第 10 行关闭;

manager id number (4);
                     ^missing

此外,您的列名中不能有空格而不引用它们。我建议用_不必在任何地方引用它们来替换空格。

SQL> create table emp
  2  (emp_id number(4),
  3  first_name varchar2(25),
  4  last_name varchar2(25),
  5  phone_number number (10),
  6  department_id number (4),
  7  job_id number (4),
  8  salary number (6,2),
  9  commission_pct number (4,2),
 10  manager_id number (4));

SQLfiddle 测试

于 2012-10-21T16:19:21.803 回答
2

我在这里发现了3个错误。

  1. 在 SQL 中,您必须使用numeric而不是数字。
  2. 你不能在字段中保留空格。
  3. 您需要关闭查询的大括号端,

代码:

 create table emp
       (emp_id numeric(4),
        first_name varchar(25),
        lastname varchar(25),
        phone_number numeric (10),
        department_id numeric (4),
        job_id numeric (4),
        salary numeric (6,2),
        commission_pct numeric (4,2),
        manager_id numeric (4))

这是SQL Fiddle 演示

于 2012-10-21T16:28:50.307 回答
2

你的列上有空格,如果你想在桌子上留下空格,用双引号括起来"

create table emp
(
   "emp id" number(4), 
   "first name" varchar2(25),
   .....
);

但最好的方法是创建列名而不在其上添加空格。

create table emp
(
   empID number(4), 
   firstName varchar2(25),
   .....
);
于 2012-10-21T16:19:31.777 回答