我正在尝试在oracle中创建表并不断收到错误。 这是我的代码。
CREATE TABLE employee
(
employeenumber INT(2) NOT NULL,
firstname CHAR(30) NOT NULL,
lastname CHAR(100) NOT NULL,
department CHAR(35) NOT NULL,
position CHAR(35) NOT NULL,
supervisor INT(2) NOT NULL,
officephone CHAR(12) NOT NULL,
emailaddress CHAR(100) NOT NULL
);
任何人都可以对我做错的事情有所了解吗?
答案 0 :(得分:2)
int
(integer
)数据类型说明符不带参数。因此,从(2)
中删除int(2)
,...等等。如果需要指定位数,请改用number(2)
。支持int
或integer
(括号中没有数字),并且为equivalent to number(38)
请参见Oracle documentation中有关数据类型的相关语法图:
答案 1 :(得分:1)
如果您使用的是SQL * Plus(而不是您使用的GUI),您会发现罪魁祸首:
SQL> CREATE TABLE employee
2 (
3 employeenumber INT(2) NOT NULL,
4 firstname CHAR(30) NOT NULL,
5 lastname CHAR(100) NOT NULL,
6 department CHAR(35) NOT NULL,
7 position CHAR(35) NOT NULL,
8 supervisor INT(2) NOT NULL,
9 officephone CHAR(12) NOT NULL,
10 emailaddress CHAR(100) NOT NULL
11 );
employeenumber INT(2) NOT NULL,
*
ERROR at line 3:
ORA-00907: missing right parenthesis
SQL>
知道了吗?删除INT的大小。
除此之外,您很可能不要使用CHAR
数据类型,但要使用VARCHAR2
。 CHAR
将使用空格正确填充所有值,直到列的全长,并引起问题。
SQL> create table employee
2 (
3 employeenumber int not null,
4 firstname varchar2(30) not null,
5 lastname varchar2(100) not null,
6 department varchar2(35) not null,
7 position varchar2(35) not null,
8 supervisor int not null,
9 officephone varchar2(12) not null,
10 emailaddress varchar2(100) not null
11 );
Table created.
SQL>
答案 2 :(得分:0)
我想这不是NUMBER。
CREATE TABLE employee
(
employeenumber NUMBER(2) NOT NULL,
firstname CHAR(30) NOT NULL,
lastname CHAR(100) NOT NULL,
department CHAR(35) NOT NULL,
position CHAR(35) NOT NULL,
supervisor NUMBER(2) NOT NULL,
officephone CHAR(12) NOT NULL,
emailaddress CHAR(100) NOT NULL
);
Table created.