我正在尝试创建一个oracle数据库。在编写以下代码并在Oracle 11g中运行它之后,它给出了一个错误,称为第1行无效字符!
SPOOL output.log;
DROP TABLE DrinkRecord CASCADE CONSTRAINTS;
/*Creates the Table */
CREATE TABLE DrinkRecord
(
ID NUMBER(11) PRIMARY KEY NOT NULL,
DrinkType VARCHAR(255) NOT NULL,
DrinkName VARCHAR(255) NOT NULL,
DrinkBenefit VARCHAR(255) NOT NULL
);
COMMIT;
/*Begin Inserting Values into the table*/
INSERT INTO DrinkRecord (ID, DrinkType, DrinkName, DrinkBenefit) VALUES (1,’Fluid’,’Water’,’life’);
COMMIT;
INSERT INTO DrinkRecord (ID, DrinkType, DrinkName, DrinkBenefit) VALUES (2,’Liquid’,’Milk’,’Strengthen bon.’);
COMMIT;
INSERT INTO DrinkRecord (ID, DrinkType, DrinkName, DrinkBenefit) VALUES (3,’Fluid’,’Ginger Ale’,’Prevent discomfort.’);
COMMIT;
INSERT INTO DrinkRecord (ID, DrinkType, DrinkName, DrinkBenefit) VALUES (4,’Fluid’,’Fish Oil’,’vitamins.’);
COMMIT;
SELECT * FROM DrinkRecord;
COMMIT;
SPOOL OFF;
运行代码时终端输出:
答案 0 :(得分:3)
您使用’
代替'
。
答案 1 :(得分:0)
唉,Oracle没有drop table if exists
或create or replace table
。这是一个简单的方法:
BEGIN
EXECUTE IMMEDIATE 'DROP TABLE DrinkRecord CASCADE CONSTRAINTS';
EXCEPTION
WHEN OTHERS THEN NULL; -- this just ignores all errors
END;
CREATE TABLE DrinkRecord . . .