无法在ubuntu命令行中运行sql文件

时间:2015-09-20 20:50:41

标签: sql oracle

我在命令行中键入了以下查询,但是当我尝试通过命令@ .... / filename.sql运行它时,第一个查询有效,但第二个查询没有...我可以'弄清楚原因。需要帮忙。 我正在阅读的错误消息 SP2-0042未知命令“)” - 忽略其余行

这是查询

/** Query 1: works through terminal and by calling @.../filename.sql**/

CREATE TABLE CUSTOMER
( cID   NUMBER NOT NULL,
  firstName     VARCHAR2(50) NOT NULL,
  lastName  VARCHAR2(50) NOT NULL,
  streetAddress VARCHAR2(50),
    CONSTRAINT CUSTOMER_PK PRIMARY KEY (customerID) 
);

/**Query2: only works through terminal**/

CREATE TABLE ADDRESS
( 
  cID   NUMBER NOT NULL,
  city          VARCHAR2(50) NOT NULL,
  zipCode       VARCHAR2(50) NOT NULL,
    CONSTRAINT FK_CUSTOMER_ADDRESS FOREIGN KEY (cID) REFERENCES CUSTOMER(cID) ON UPDATE CASCADE

);

2 个答案:

答案 0 :(得分:1)

SQL Plus不喜欢DDL中间的空行(对于非过程对象)。删除右括号前的空行或在运行该DDL之前运行set sqlblanklines on

答案 1 :(得分:1)

Oracle不支持ON UPDATE CASCADE,它只支持ON DELETE CASCADE

https://docs.oracle.com/cd/E11882_01/server.112/e41084/clauses002.htm#CJAIHHGC

除了空行(Allan已经指出)之外,你需要删除外键的ON UPDATE CASCADE