我在Oracle中的查询一直在说我缺少一个逗号错误。我看不到任何逗号。请帮助
INSERT INTO TBLTEACHER (TEACHERID,FIRSTNAME,SURNAME,LOGINUMBER,COURSEID) VALUES
(100,"Jessica, Janet, Robert, Jonathon","Davies, Smith, Clarkson, Campbell",2i,1),
(101,"Jessica, Janet, Robert, Jonathon","Davies, Smith, Clarkson, Campbell",6i,2),
(102,"Jessica, Janet, Robert, Jonathon","Davies, Smith, Clarkson, Campbell",10i,3),
(103,"Jessica, Janet, Robert, Jonathon","Davies, Smith, Clarkson, Campbell",14i,4),
答案 0 :(得分:1)
Oracle不允许使用值插入多个行。因此,请使用多个插入内容。
此外,Oracle不支持字符串的双引号。除非它是字符串,否则类似2i
的东西是没有意义的。因此,以下内容似乎将插入您想要的行:
INSERT INTO TBLTEACHER (TEACHERID,FIRSTNAME,SURNAME,LOGINUMBER,COURSEID)
VALUES (100, 'Jessica, Janet, Robert, Jonathon', 'Davies, Smith, Clarkson, Campbell', '2i', 1);
INSERT INTO TBLTEACHER (TEACHERID,FIRSTNAME,SURNAME,LOGINUMBER,COURSEID)
VALUES (101, 'Jessica, Janet, Robert, Jonathon', 'Davies, Smith, Clarkson, Campbell', '6i',2);
INSERT INTO TBLTEACHER (TEACHERID,FIRSTNAME,SURNAME,LOGINUMBER,COURSEID)
VALUES (102, 'Jessica, Janet, Robert, Jonathon', 'Davies, Smith, Clarkson, Campbell', '10i', 3);
INSERT INTO TBLTEACHER (TEACHERID,FIRSTNAME,SURNAME,LOGINUMBER,COURSEID)
VALUES (103, 'Jessica, Janet, Robert, Jonathon', 'Davies, Smith, Clarkson, Campbell', '14i', 4);
我发现将列表放入字符串中并插入它们很奇怪,但这是另一回事。
答案 1 :(得分:0)
您可以转换为带有全部并集子句的select语句,并用单引号替换双引号,然后将其他非带引号的字母数字值转换为单引号:
INSERT INTO TBLTEACHER (TEACHERID,FIRSTNAME,SURNAME,LOGINUMBER,COURSEID)
SELECT 100,'Jessica, Janet, Robert, Jonathon','Davies, Smith, Clarkson, Campbell','2i' ,1 FROM dual UNION ALL
SELECT 101,'Jessica, Janet, Robert, Jonathon','Davies, Smith, Clarkson, Campbell','6i' ,2 FROM dual UNION ALL
SELECT 102,'Jessica, Janet, Robert, Jonathon','Davies, Smith, Clarkson, Campbell','10i',3 FROM dual UNION ALL
SELECT 103,'Jessica, Janet, Robert, Jonathon','Davies, Smith, Clarkson, Campbell','14i',4 FROM dual;
或者使用INSERT ALL
子句:
INSERT ALL
INTO TBLTEACHER VALUES(100,'Jessica, Janet, Robert, Jonathon','Davies, Smith, Clarkson, Campbell','2i' ,1)
INTO TBLTEACHER VALUES(101,'Jessica, Janet, Robert, Jonathon','Davies, Smith, Clarkson, Campbell','6i' ,2)
INTO TBLTEACHER VALUES(102,'Jessica, Janet, Robert, Jonathon','Davies, Smith, Clarkson, Campbell','10i',3)
INTO TBLTEACHER VALUES(103,'Jessica, Janet, Robert, Jonathon','Davies, Smith, Clarkson, Campbell','14i',4)
SELECT 1 FROM dual;
P.S。如果VALUES
子句中逗号分隔的组件数等于表的列数,则无需显式地编写它们。