我在运行SQL数据库时遇到问题,我想创建一个像数据库一样的youtube。我收到了这个错误。
CREATE TABLE `Like` ( `video_id` int(5) NOT NULL DEFAULT '0', `customer_id` int(6) NOT NULL DEFAULT '0', `rating` int(1) NOT NULL DEFAULT '0', `date` date NOT NULL DEFAULT '0000-00-00', PRIMARY KEY (`video_id`,`customer_id`), KEY `date` (`date`), KEY `video_id` (`video_id`), KEY `customer_id` (`customer_id`), KEY `rating` (`rating`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1
Error report -
SQL Error: ORA-00911: invalid character
00911. 00000 - "invalid character"'
*Cause: identifiers may not start with any ASCII character other than
letters and numbers. $#_ are also allowed after the first
character. Identifiers enclosed by doublequotes may contain
any character other than a doublequote. Alternative quotes
(q'#...#') cannot use spaces, tabs, or carriage returns as
delimiters. For all other contexts, consult the SQL Language
Reference Manual.
*Action:
CREATE TABLE `movies` ( `id` int(5) NOT NULL DEFAULT '0', `year` int(4) DEFAULT '0', `title` varchar(255) NOT NULL DEFAULT '', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
CREATE TABLE `Channel` ( `movie_id` int(5) NOT NULL DEFAULT '0', `customer_id` int(6) NOT NULL DEFAULT '0', KEY `movie_id` (`movie_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
CREATE TABLE `qualifying` ( `customer_id` int(6) NOT NULL DEFAULT '0', `date` date NOT NULL DEFAULT '0000-00-00', `movie_id` int(5) NOT NULL DEFAULT '0', KEY `movie_id` (`movie_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
CREATE TABLE `Like` ( `video_id` int(5) NOT NULL DEFAULT '0', `customer_id` int(6) NOT NULL DEFAULT '0', `rating` int(1) NOT NULL DEFAULT '0', `date` date NOT NULL DEFAULT '0000-00-00', PRIMARY KEY (`video_id`,`customer_id`), KEY `date` (`date`), KEY `video_id` (`video_id`), KEY `customer_id` (`customer_id`), KEY `rating` (`rating`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
答案 0 :(得分:1)
您的主要问题是您正在尝试在Oracle数据库上运行带有MySQL语法的SQL脚本(您显然是在Oracle数据库上,因为您收到ORA-00911
错误)。
您可以使用Oracle语法编写脚本,也可以更改数据库并使用MySQL。
答案 1 :(得分:0)
从您的错误消息和脚本中可以清楚地看到,您正试图在Mysql
数据库中运行Oracle
表脚本,这就是为什么你收到了错误。
您需要在表脚本中进行一些更改,以便在Oracle
数据库中进行更改
back-ticks
替换为double quotes(")
int(N)
数据类型替换为Number(P)
示例
CREATE TABLE "like"
(
"video_id" Number(10) NOT NULL DEFAULT '0',
"customer_id"Number(10) NOT NULL DEFAULT '0',
"rating" Number(10) NOT NULL DEFAULT '0',
"date" DATE NOT NULL DEFAULT '0000-00-00',
CONSTRAINT video_customers_pk PRIMARY KEY ("video_id", "customer_id")
KEY "date"("date"), -- Not sure how to change this in oracle
KEY video_id("video_id"),
KEY customer_id("customer_id"),
KEY rating("rating")
)
注意:我不确定KEY video_id("video_id")
Oracle
的等效内容